[英]CSS: Preventing single symbols from wrapping to a new line
I'm presenting a long list of links wrapped in a div with middle dots separating each item (specifically, [space]·[space]
between each link). 我正在展示一长串的链接,这些链接包裹在div中,中间的点分隔每个项目(特别是每个链接之间的[space]·[space]
)。 Occasionally, a dot appears at the beginning of a line, as shown here: 有时,在行的开头会出现一个点,如下所示:
link · link · link · link · link · link · link · link · link · link · link · link · link · link · link · link · link · link · link · link · link · link · · link · link · link · link · link · link · link · link · link · link · link
Is there a way to prevent this? 有办法防止这种情况吗? I've tried various white-space
property values. 我尝试了各种white-space
属性值。 Right now, each link is wrapped inside a <span>
tag that uses whiite-space: pre-wrap;
现在,每个链接都包装在使用whiite-space: pre-wrap;
的<span>
标记whiite-space: pre-wrap;
in its class, which so far has given the best results (ie, the fewest wrapped dots). 在同类产品中,迄今为止效果最好(即,包裹的点最少)。
Alternatively, if there's a better way to display such a list, I'm open the suggestions. 或者,如果有更好的方法来显示此类列表,请打开建议。
Assuming that all your links have link text, you need the dot to stay on the same line as the preceding link. 假设所有链接都具有链接文本,则您需要将点保持在与前面的链接相同的行上。
A simple fix is to use a non-breaking space in your mark-up: 一个简单的解决方法是在标记中使用不间断的空格:
<a href="">link</a> &midot;
or use pseudo elements: 或使用伪元素:
a:after { content:'\\A0\\B7'; /* Hex codes for nbsp and midot */ }
<a href"">link</a><a href"">link</a><a href"">link</a><a href"">link</a>
You could add the "dot" using pseudo content. 您可以使用伪内容添加“点”。 Using an :after
selector, it would never fall to the next line alone... 使用:after
选择器,它永远不会掉到下一行...
#wrapper { width: 150px; } #wrapper span:after { content: "."; padding: 0 5px; }
<div id="wrapper"> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> <span>link</span> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.