HTML 字符 - 不可见空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20760772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML Character - Invisible space
提问by Isaiah
I have a website called DaltonEmpire.
我有一个叫道尔顿帝国的网站。
When a user copies "DaltonEmpire" I would like "Dalton Empire" to be added to their clipboard.
当用户复制“DaltonEmpire”时,我希望将“Dalton Empire”添加到他们的剪贴板中。
I only came to one solution; use a space, but make the letter-spacing
-18px
.
Isn't there a neater solution, such as a HTML character for this?
我只找到了一个解决方案;使用空格,但使letter-spacing
-18px
. 没有更简洁的解决方案,例如用于此的 HTML 字符吗?
My example JSFiddleand code:
我的示例JSFiddle和代码:
span.nospace {
letter-spacing: -18px;
}
<ol>
<li>Dalton<b>Empire</b></li>
<li>Dalton‌<b>Empire</b></li>
<li>Dalton‍<b>Empire</b></li>
<li>Dalton​<b>Empire</b></li>
<li>Dalton<span class="nospace"> </span><b>Empire</b> <i>The only one that works</i>
</li>
</ol>
采纳答案by nkmol
You can use word-spacing
for this. However to make a more dynamic property you want to use the em
unit. This way the unit is based on the font-size, so actually supports all the font families andfont sizes:
您可以word-spacing
为此使用。但是,要使您想要使用该em
单位的更动态的属性。这样单位是基于字体大小的,所以实际上支持所有的字体系列和字体大小:
ol li
{
word-spacing: -.2em;
}
em is not an absolute unit - it is a unit that is relative to the currently chosen font size.
em 不是绝对单位 - 它是相对于当前选择的字体大小的单位。
source: Why em instead of px?
jsFiddle
js小提琴
回答by user3096206
Are you looking something like this:
你是不是看起来像这样:
HTML space:
?
HTML 空间:
?
回答by skibulk
Here is some interesting and related info. It doesn't solve your problem, but it may help people who are searching for a way to create an optional line-break, like I was. The Zero-Width Space ​
and <wbr>
element are two possible options.
这是一些有趣的相关信息。它不能解决您的问题,但它可能会帮助那些正在寻找创建可选换行符的方法的人,就像我一样。零宽度空间​
和<wbr>
元素是两个可能的选项。
回答by Bhojendra Rauniyar
回答by AVAVT
How about this? Looks neat enough to me:
这个怎么样?对我来说看起来很整洁:
ol li{
word-spacing: -4px; /* just enter an appropriate amount here */
}
You can now remove the nospace span.
您现在可以删除 nospace 跨度。