How to prevent line breaks in list items using CSS

≡放荡痞女 提交于 2019-11-26 21:17:29
n1313

Use white-space: nowrap;1, or give that link more space by setting li's width to greater values.

JimmyRare

You could add this little snippet of code to add a nice "…" to the ending of the line if the content is to large to fit on one line:

li {
  overflow: hidden; 
  text-overflow: ellipsis;
  white-space: nowrap;
}
ptim

If you want to achieve this selectively (ie: only to that particular link), you can use a non-breaking space instead of a normal space:

<li>submit&nbsp;resume</li>

https://en.wikipedia.org/wiki/Non-breaking_space#Encodings

edit: I understand that this is HTML, not CSS as requested by the OP, but some may find it helpful…

display: inline-block; will prevent line breaks in list items

http://jsfiddle.net/Nash171/mwe4s0nc/46/

 li{
    display: inline-block;
 }

Bootstrap 4 has a class named text-nowrap. It is just what you need.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!