Html 自动换行在 LI 元素中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22061287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 01:04:11  来源:igfitidea点击:

Word-wrap not working in LI element

htmlcsstwitter-bootstrap

提问by user3322300

I want to wrap the words automatically within width.

我想在宽度内自动包装单词。

<ul class="dropdown-menu" style="width:298px;margin:15px 0 0 0;">
     <li>option 1 </li>
     <li>option 2 option 2 option 2 option 2 option 2 option 2</li>
</ul>

It's now working fine with white-space:normal

它现在工作正常 white-space:normal

ul li{
     white-space:normal;
}

回答by Piyush Marvaniya

Please Try it...

请尝试一下...

ul li {
    word-break: break-all;
}

回答by David M

Add white-space:normal to your CSS element:

将 white-space:normal 添加到您的 CSS 元素中:

  word-break: normal;
  white-space: normal;

回答by Michael OConnor

This works well for me as it wraps correctly with or without whitespace:

这对我来说很有效,因为它可以正确包装或不使用空格:

li {
    word-break: break-all;
    }

回答by Alex

use word-wrap:break-word;works perfectly fine for me here is the jsfiddle

使用word-wrap:break-word;对我来说非常好,这里是jsfiddle