【问题标题】:How can I format a paragraph with a <br /> tag in it as justified? [duplicate]如何格式化带有 <br /> 标记的段落以证明其合理性? [复制]
【发布时间】:2020-07-29 19:37:04
【问题描述】:

我的代码:

<h1>example</h1>
<p align="justify">John&rsquo;s family is living in a tiny flat. That would not be too bad. But unfortunately John is longing for a dog to play and fool arount with. There isn&rsquo;t any space for a dog in the small attic. How can John&rsquo;s dream come true? The little
  mermaid is searching for <br /> a friend who is exactly like her. Unfortunately she cannot find an other mermaid in the ocean. So she has to stay all alone. Or is there any solution for this problem?
</p>

Result: 带有&lt;br /&gt; 标签的行的格式不正确。

重要的是,除最后一行之外的所有行都被格式化为 有道理。

单词之间的间隔大小并不重要。

换行符必须准确地保留在那里。

我尝试了 HTML 和 CSS。 我用谷歌搜索并在论坛中寻找类似的问题。 没有成功。


自行解决:

与:

text-align: justify;
text-align-last: justify;

在 CSS 中有效!!!

【问题讨论】:

  • 似乎很奇怪它不是两个段落标签。
  • @epascarello - 就像一首诗。每个换行符都是有意义的。但是每个段落都应该被证明是合理的。 - 加上文本来自 mysql 通过 php 并且已经有换行符。
  • 设置一个宽度,看看区别。
  • @Sam Herrmann - 这个问题/答案已经有将近 6 年的历史了,并且存在以下问题:“但是,如果段落的其余部分不适合一行,它将溢出您的宽度设置。”
  • 来自副本:stackoverflow.com/a/63062369/8620333 ...问题的年龄无关紧要,有新的答案

标签: html css


【解决方案1】:

您需要在文本的最后一点周围再添加一个&lt;p&gt; 标记。之后你可能想也可能不想调整段落之间的间距。

此外,您还需要检查&lt;p&gt; 标签的父元素的宽度。根据父元素的宽度,它可能会也可能不会导致文本环绕到下一行。

<body>
<h1>example</h1>
<p align="justify">John&rsquo;s family is living in a tiny flat. That would not be too bad. But unfortunately John is longing for a dog to play and fool arount with. There isn&rsquo;t any space for a dog in the small attic. How can John&rsquo;s dream come true? The little mermaid is searching for <br/></p>
<p align="justify"> a friend who is exactly like her. Unfortunately she cannot find an other mermaid in the ocean. So she has to stay all alone. Or is there any solution for this problem?</p>
</body>

【讨论】:

  • 如果我有 3 个句子 - 每个句子在一行中,每一行都应该是合理的。我该怎么做?
  • 如何将一行格式化为合理的?
  • 如果你让每个句子占一行,那么我建议让每个句子都有自己的&lt;p&gt;标签。这样,您可以将align="justify" 添加到每个&lt;p&gt; 标记中。
猜你喜欢
  • 2017-09-11
  • 1970-01-01
  • 1970-01-01
  • 2014-12-15
  • 2011-03-18
  • 1970-01-01
  • 2017-08-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多