[英]Wrap the words to a new line
I have a problem to display the content of p inside a div . 我在显示div中p的内容时遇到问题。 If my p is too long, i wish to break it down to a new line.
如果我的p太长,我希望将其细分为新的一行。 But right now, it just keep stretching.
但是现在,它一直在延伸。 How can I fix it to display as the block within a div?
我如何解决它显示为div中的块? Thank you.
谢谢。
.box { position: relative; width: 25%; padding-bottom: 25%; background: #fff; } .boxInner { position: absolute; left: 5px; right: 5px; top: 5px; bottom: 5px; overflow: hidden; } .boxInner img { width: 100%; } .boxInner .titleBox { background: #000; background: rgba(0, 0, 0, 0.9); color: #FFF; padding: 10px; text-align: center; height: 42%; position: absolute; display: block; } .titleBox1 { top: 0; left: 0; right: 0; } .titleBox2 { bottom: 0; left: 0; right: 0; }
<div class="box"> <div class="boxInner"> <div class="titleBox titleBox1" > <p> asdasdasdasdddddddddasdddddddddddddddddddd </p> </div> <img src="http://www.dwuser.com/education/content/creating-responsive-tiled-layout-with-pure-css/images/demo/1.jpg" /> <div class="titleBox titleBox2">An old greenhouse</div> </div> </div>>
Your p
element content is asdasdasdasdddddddddasdddddddddddddddddddd
, which does not contain any permissible line breaking points. 您的
p
元素内容为asdasdasdasdddddddddasdddddddddddddddddddd
,其中不包含任何允许的断点。 You need to define where and how it may be broken and then insert eg either zero-width spaces or soft hyphens. 您需要定义可能在何处以及如何破坏它,然后插入零宽度空格或软连字符。 If you need help with this, you should post a description of your real content in the
p
element, illustrated with real examples, and specify the principles according to which it can be broken. 如果您需要帮助,则应在
p
元素中发布对真实内容的描述(以实际示例为例),并指定可以打破其内容的原则。
add something to the css class 在CSS类中添加一些内容
p{ word-wrap:break-word;
p {word-wrap:break-word; width:100px;
宽度:100px; }
}
I think word-wrap can't work well without setting width in css. 我认为如果不在CSS中设置宽度,自动换行就无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.