简体   繁体   English

文字未在div元素内换行

[英]Text not wrapping inside div element

I have tried every CSS setting I can find but I cannot get the text in this div to wrap! 我已经尝试了所有可以找到的CSS设置,但是无法获取该div中的文本来包装! I'd appreciate some help as this is my first time working with HTML in like 10 years. 我希望能获得一些帮助,因为这是我十年来第一次使用HTML。 Here's my latest attempt: 这是我最近的尝试:

 #text0 { word-break: break-word; max-width: 500px; width: 500px; word-wrap: break-word; overflow: hidden; white-space: pre; background-color: #afed67; } 
 <div id="text0"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scramble it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </div> 

BTW this all has to go into a Wordpress page, I know they can be finnicky about CSS and JavaScript. 顺便说一句,所有这些都必须进入Wordpress页面,我知道他们对CSS和JavaScript可能很敏感。

Check this snippet out. 查看此代码段。 You just need the word-break and the width 您只需要word-breakwidth

 #text0 { word-break: break-word; width: 500px; background-color: #afed67; } 
 <div id="text0"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scramble it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </div> 

Is the below what you are expectiing- see the CSS I used: 以下是您期望的-请参阅我使用的CSS:

#text0 {
  word-break: break-word;
  max-width: 500px;
  width: 500px;
  background-color: #afed67;
  line-height: 25px;
}

snippet below: 下面的代码段:

 #text0 { word-break: break-word; max-width: 500px; width: 500px; background-color: #afed67; line-height: 25px; } 
 <div id="text0"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scramble it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. </div> 

It's overflow:hidden; overflow:hidden; and white-space:pre; white-space:pre; that are messing you up there. 那把你搞砸了 Remove them and you'll be fine. 删除它们,您会没事的。

Divs have overflow:wrap; Divs overflow:wrap; , and white-space:normal; ,和white-space:normal; by default, which is the behaviour you want. 默认情况下,这是您想要的行为。

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

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