如何使用 CSS 防止列表项换行

发布于 2024-08-03 11:41:50 字数 88 浏览 2 评论 0原文

我正在尝试使用 li 标记在菜单中放置一个名为“提交简历”的链接。由于两个单词之间有空格,它会换行为两行。如何用 CSS 防止这种换行?

I'm trying to put a link called Submit resume in a menu using a li tag. Because of the whitespace between the two words it wraps to two lines. How to prevent this wrapping with CSS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

无人问我粥可暖 2024-08-10 11:41:50

如果内容太大而无法容纳在一行中,您可以添加这一小段代码,以在行末尾添加一个漂亮的“...”:

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

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;
}
心头的小情儿 2024-08-10 11:41:50

如果您想有选择地实现此目的(即:仅针对该特定链接),您可以使用不间断空格而不是普通空格:

<li>submit resume</li>

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

编辑:我知道这是 HTML,而不是 OP 所要求的 CSS ,但有些人可能会发现它有帮助......

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 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…

不再见 2024-08-10 11:41:50

display: inline-block; 将防止列表项中的单词之间出现中断:

li {
  display: inline-block;
}

display: inline-block; will prevent break between the words in a list item:

li {
  display: inline-block;
}
时光沙漏 2024-08-10 11:41:50

Bootstrap 4 有一个名为 text-nowrap 的类。这正是您所需要的。

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

后知后觉 2024-08-10 11:41:50

在 CSS 中,空白 可以完成这项工作

可能的值:

white-space: nowrap
white-space: pre
white-space: pre-wrap
white-space: pre-line
white-space: break-spaces
white-space: normal

In your CSS, white-space can do the job

possible values:

white-space: nowrap
white-space: pre
white-space: pre-wrap
white-space: pre-line
white-space: break-spaces
white-space: normal
弄潮 2024-08-10 11:41:50

your text (不是 css,但在某些情况下更容易)

<nobr>your text</nobr> (not css but easier in some cases)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文