html - li 上的“自动换行”而不是单个单词

标签 html css html-lists

我正在生成一个标签列表(采用 ul/li 格式),我希望在 li 上出现换行符而不是 li 中的单个单词或字符.

到目前为止,我发现唯一可以执行任何操作的 css 命令是 word-break如果是break-all它会在任何字符后中断,normal (或默认为 normal 的任何其他内容)在空格或破折号后中断 -

Fiddle

目前我的css如下:

li { 
  display: inline;
  line-height: 24px !important;
  border: 1px solid black;
  word-break: normal;
}

最佳答案

如果我没理解错的话,你只需要将li设置为display:inline-block

li {
  display: inline-block;
  line-height: 24px;
  border: 1px solid black;
}
<ul>
  <li>This longword tag One</li>
  <li>This longword tag Two</li>
  <li>ThislongwordtagThree</li>
  <li>This longword tag Four</li>
  <li>This longword tag Five</li>
  <li>This longword tag Six</li>
  <li>This longword tag Seven</li>
</ul>
<ul>
  <li>This longword tag One</li>
  <li>This longword tag Two</li>
  <li>ThislongwordtagThree</li>
  <li>This longword tag Four</li>
  <li>This longword tag Five</li>
  <li>This longword tag Six</li>
  <li>This longword tag Seven</li>
</ul>

关于html - li 上的“自动换行”而不是单个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37778554/

相关文章:

html - 无论图像的分辨率如何,格式化卡中的图像大小

javascript - 将 JS Div react 为 png 或捕获 Div

html - 将 div 放在 <li> 和 <a> 之上,但不要移动它们的位置

javascript - 如何在纯javascript中点击时获取li元素内的文本

html - 用按钮替换 ul 子弹

javascript - 如何在两个 parent 之间转换一个div?

Jquery UI Datepicker 不适用于 bootstrap 和 Firefox

javascript - BigCommerce 添加事件菜单类

html - 位置符号的 HTML 实体是什么

html - 如何在 contentPlaceholder 中引用具有特定 ID 的按钮