我有一个包含多个<p>
元素的<span>
元素,我试图在容器包装的任何地方添加换行符。但是,它目前在跨度上打破。
视觉示例:
Lorem Ipsum Dolor |
Sit amet |
conseceteuerblabla |
我努力实现的目标:
Lorem Ipsum Dolor Si|
t amet conseceteuerb|
labla |
如何使用相同的标记来实现这一目标?
我的代码:
p {
font-family: monospace;
font-size: calc(2em + 3vw);
word-break: break-word;
}
span {
word-break: break-word;
}
&#13;
<p>
<span>Lorem</span>
<span>Ipsum</span>
<span>Dolor</span>
<span>Sit</span>
<span>azerty</span>
<span>qwerty</span>
<span>asdfghjk</span>
<span>qwertyuiopasdfghjkl</span>
</p>
&#13;
答案 0 :(得分:3)
break-word
不是word-break
的有效值。您必须使用break-all
p {
font-family: monospace;
font-size: calc(2em + 3vw);
word-break: break-all;
}
span {
word-break: break-all;
}
&#13;
<p>
<span>Loremloremlorem</span>
<span>Ipsumipsumipsumipsm</span>
<span>Dolordolordolordolordolordolor</span>
<span>Sitsitsitsitsitsitsit</span>
<span>asdasdasdsadasdasdasdasdasd</span>
<span>qweqweqweqw</span>
<span>zxc</span>
<span>tyutyutyutyutyutyutyutyu</span>
</p>
&#13;
答案 1 :(得分:0)
你可以使用
P{
word-break: break-all;
}
而不是word-break:break-word;