HTML 使用
 对齐文本对齐标签

发布于 2024-12-28 00:43:49 字数 745 浏览 4 评论 0原文

我对格式和固定宽度的段落内的文本对齐“对齐”有疑问,因为我希望 HTML 中的段落文本显示完全对齐(就像 MS Word 文件中发生的情况一样)。然而,这并没有发生。我需要修改什么才能实现它?

     <pre style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: medium; width: 500px; text-align: justify;"> 

I have a problem with the text-align "justify" inside a paragraph with format and fixed width, because I want the paragraph text in HTML to appear totally justified (like it would happen with a MS Word file). However, this does not happen. What I need to modify to achieve it?

        </pre>

编辑:如果我用

标记替换

 标记,我的代码可以正常工作。有人可以解释一下为什么吗?也许我错误地使用了 
 标签。

I have a problem with the text-align "justify" inside a paragraph with format and fixed width, because I want the paragraph text in HTML to appear totally justified (like it would happen with a MS Word file). However, this does not happen. What I need to modify to achieve it?

     <pre style="color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: medium; width: 500px; text-align: justify;"> 

I have a problem with the text-align "justify" inside a paragraph with format and fixed width, because I want the paragraph text in HTML to appear totally justified (like it would happen with a MS Word file). However, this does not happen. What I need to modify to achieve it?

        </pre>

EDIT: if I replace the <pre> tag with <p> tag, my code works properly. Can somebody explain me why? Perhaps I am using a wrong use of <pre> tag.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

千柳 2025-01-04 00:43:49
  pre {
    text-align: left;
    white-space: pre-line;
  }
  pre {
    text-align: left;
    white-space: pre-line;
  }
戏舞 2025-01-04 00:43:49

要对齐

 中的文本,您需要在样式中添加 white-space: normal; ,但在我看来,这忽略了使用 < ;pre> 标签。

-- 编辑 --

您可以使用具有适当样式的

来代替

 标记。它可以很好地模仿 
 标签,并且更容易使用。

To justify text in <pre> you need to add white-space: normal; in your styles, but in my opinion this misses the point using the <pre> tag.

-- Edit --

Instead of <pre> tag you can just use <div> with appropriate styles. It can imitate <pre> tag very well and is easier to play with.

不语却知心 2025-01-04 00:43:49

使用标签:

<pre><code>
Your text
Your text
</code></pre>

删除文本前面的所有空格和所有缩进。

Use tags:

<pre><code>
Your text
Your text
</code></pre>

Remove all spaces preceding your text, all indentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文