css - 如何防止标签自动换行?

标签 css tags word-break nowrap

我有很多标签不想自动换行,但我确实想要让标签列表自动换行。 例如:

[first] [second thing] [yet another thing]

我不想要的是:

[first] [second 
thing] [yet another thing]

即打破标签

我想要的是这样的:

[first] [second thing] 
[yet another thing]

我搞砸了

word-break: break-word;
/* white-space: nowrap; */

在父子上,没有任何成功。 要么整个​​字段结束为一行 - 根本没有中断,要么我在标签内中断。

目前我有这个:

.tag-box {
  word-break: break-word;
}

.tag {
  color: white;
  background: #000;
  border: 1px solid white;
  border-radius: 5px;
  margin-bottom: 10px;
  margin-right: 5px;  
  padding: 5px;
  line-height: 200%;
  /* word-break: break-word; */
  /* white-space: nowrap; */
}

最佳答案

这是一个 fiddle :http://jsfiddle.net/5fev6o2p/6/

CSS 代码:

.tag-box {
  word-break: break-word;
}

.tag {
  color: white;
  background: #000;
  border: 1px solid white;
  border-radius: 5px;
  margin-bottom: 10px;
  margin-right: 5px;  
  padding: 5px;
  line-height: 200%;
  display:inline-block;
}

HTML:

<ul class="tag-box">
  <li class="tag">[first]</li>
  <li class="tag">[second thing]</li>
  <li class="tag">[third thing]</li>
  <li class="tag">[yet another thing]</li>
  <li class="tag">[first]</li>
  <li class="tag">[second thing]</li>
  <li class="tag">[third thing]</li>
  <li class="tag">[yet another thing]</li>
</ul>

关于css - 如何防止标签自动换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51576355/

相关文章:

html - 如何防止固定布局表格单元格中的断字?

html - 在 css 选择器中使用 ">"有什么区别(和优点,如果有的话)?

jquery - typist.js while lines expanding the page scrolling bottom

php - 页面无法在 IE8 中正确呈现

docker - 如何在 docker-compose 中使用多个图像标签

javascript - 这是什么类型的 HTML 标签 <gcse :search>?

jquery - 位置 :fixed not being appended in ie

c# - 使用 LibTiff.Net 2.3 库时如何使 StripOffsets 标记保持不变?

css - Firefox 中没有一致的断字

css - `word-break: break-word` 的替代品