简体   繁体   English

自动换行不适用于浮动文本

[英]word-wrap not working on a floating text

Let's say I have this. 假设我有这个。

<div>
<div id="lala">
lalalala
</div>
</div>

css: CSS:

#lala
{
   float:left;
   word-wrap:break-word;
}

if the text inside #lala is big, it will look like this. 如果#lala的文本很大,它将如下所示。

|                              |
|                              |
| lalalalalalalalalalalalalala | lalalalalala <-- these won't be show.
|                              |
|                              |

If I remove float:left; 如果我删除float:left; this will be the result. 这将是结果。

|                              |
|                              |
| lalalalalalalalalalalalalala |
| lalalalalala                 |
|                              |

How can I have the second result while still using float? 如何在使用float时获得第二个结果?

give the element a fixed width so we know where to break the word: 给元素一个固定的宽度,以便我们知道在哪里打破这个词:

#lala
{
float:left;
word-wrap:break-word;
width:?px;
}

The word-wrap:break-word property should only apply if the element has a visual rendering, is an inline element with explicit height/width, is absolutely positioned and/or is a block element. word-wrap:break-word属性应仅在元素具有可视化渲染时应用,是具有显式高度/宽度的内联元素,绝对定位和/或是块元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM