【发布时间】:2013-01-24 21:43:45
【问题描述】:
我创建了一个容器来将我的内容居中放置在页面中间,但我遇到了一个问题,即段落标签从容器 div 中延续出来并且不会自动换行。我总是发现容器可以使用包装,我从来没有遇到过这个问题。
.container { width: 1000px; margin: 0 auto; }
这是从 div.container 元素中浮出的 HTML
<div class="container">
<p>TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest</p>
</div>
【问题讨论】:
-
这是因为
<p>元素内没有中断字符。 -
使用百分比而不是硬编码的 px 值。
width:1000px->width:100% -
@Alpay 这毫无意义
-
很抱歉我的问题弄错了。您的字符串继续在容器外的原因是,您的字符串没有任何空格字符,并且 html 解析器不知道在哪里分解该字符串。所以对于这种情况,你必须按照建议使用
word-wrap: break-word;CSS 属性。 -
太好了,谢谢你的详细解释。