简体   繁体   English

如何在新行上强制链接?

[英]How to force a link on a new line?

I have a sequence of html links, some long and some short.我有一系列 html 链接,有些长有些短。 Now my problem is I don't want the link to break to a new line in the middle, I want it to just go to the new line.现在我的问题是我不希望链接在中间断开到新行,我希望它只是转到新行。 Right now some of my links (a sequence of words which can be 5 or 6 words long) have the annoying behaviour of breaking to a new line right in the middle.现在我的一些链接(可以是 5 或 6 个单词长的单词序列)有令人讨厌的行为,即在中间换行。

Makes sense?说得通?

can you help?你能帮我吗? Thx!谢谢!

Try this:尝试这个:

a {
  white-space: nowrap;
}

Here's an example on jsfiddle .这是一个关于 jsfiddle例子

You should be able to do that with <nobr><a ...</a></nobr> , which is deprecated as Sn0opy pointed out.您应该可以使用<nobr><a ...</a></nobr>来做到这一点,正如 Sn0opy 指出的那样,它已被弃用。

You should do it via CSS:你应该通过 CSS 来做:

a { 
    white-space: nobreak; 
}

You can set the anchor's display attribute in css to block.可以在css中设置anchor的display属性为block。 Here is a working sample .这是一个工作示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM