Html , , Safari 浏览器中的替代品
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28058735/
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
 ,  ,   alternatives in Safari browser
提问by kipid
 ,  ,   are broken in Safari browser.
, , 在 Safari 浏览器中坏了。
These are thin space, n-size space, m-size space which works in other browsers.
这些是适用于其他浏览器的细空间、n 大小空间、m 大小空间。
thinsp : a b c d e f g
Thinsp : a b c d e f g
ensp : a b c d e f g
ensp : a b c d e f g
emsp : a b c d e f g
emsp : a b c d e f g
Are there alternatives for these in Safari?
Safari 中是否有这些替代品?
采纳答案by Jukka K. Korpela
This could be a font problem; it might help to specify a font that contains glyphs for the fixed-width spaces used. Most fonts lack them. Good browsers don't need the glyphs but instead increase spacing between other characters.
这可能是字体问题;为使用的固定宽度空间指定包含字形的字体可能会有所帮助。大多数字体都缺少它们。好的浏览器不需要字形,而是增加其他字符之间的间距。
However, a more robust approach is to use CSS techniques for adding spacing, mainly the padding
properties and, for runs of text where specific spacing is desired between all letters, the letter-spacing
property. Using the latter, note that it adds spacing after the last character, too. My page on Unicode spacesshows the defined or typical widths of “fixed-width spaces” like THIN SPACE (which aren't all really fixed-width). But it is probably better to start from the amount of desired spacing, in terms of the em
unit (font size), and just forget the fixed-width spaces.
然而,更强大的方法是使用 CSS 技术来添加间距,主要是padding
属性,对于所有字母之间需要特定间距的文本运行,letter-spacing
属性。使用后者,请注意它也在最后一个字符之后添加了间距。我的Unicode 空间页面显示了“固定宽度空间”的定义或典型宽度,例如 THIN SPACE(并非所有真正的固定宽度)。但最好从所需的间距量开始,就em
单位(字体大小)而言,而忘记固定宽度的空格。
Yet another possibility is to use the normal SPACE character but wrap it in a span
and set its width. This requires making it an inline block. The approach is better than the above when the desired non-CSS fallback is a regular space rather than lack of any spacing. Note that search engines should be assumed CSS-ignorant, so this approach is relevant to making them “see” a word space between characters (e.g. to see “foo bar” and not “foo bar” when you want a fixed-width space between the words “foo” and “bar”). And as usual, you can use NO-BREAK SPACE instead of SPACE in order to prevent line break.
另一种可能性是使用普通的 SPACE 字符,但将其包裹在 a 中span
并设置其宽度。这需要使其成为内联块。当所需的非 CSS 回退是常规空间而不是缺少任何间距时,该方法比上述方法更好。请注意,搜索引擎应该被假定为对 CSS 一无所知,因此这种方法与使它们“看到”字符之间的单词空间有关(例如,当您想要之间的固定宽度空间时,看到“foo bar”而不是“foo bar”单词“foo”和“bar”)。和往常一样,您可以使用 NO-BREAK SPACE 代替 SPACE 以防止换行。
Example:
例子:
.thin {
display: inline-block;
width: 0.2em;
}
<div style="font-size: 200%">
<div>a b (normal space)</div>
<div>a b (thin space)</div>
<div><span style="padding-right: 0.2em">a</span>b (0.2em padding)</div>
<div><span style="letter-spacing: 0.2em">ab</span> (0.2em letter spacing)</div>
<div>a<span class=thin> </span>b (space set to 0.2em width)</div>
<div>a<span class=thin> </span>b (no-break space set to 0.2em width)</div>
</div>
回答by Dave Burton
This problem seems to be fixed. I cannot reproduce it, anyhow. I tested with four common fonts. Here's the test page:
这个问题似乎是固定的。无论如何,我无法重现它。我用四种常见字体进行了测试。下面是测试页面:
http://burtonsys.com/test_html_spaces.html
http://burtonsys.com/test_html_spaces.html
I don't have an Apple device, but I used a couple of cross-browser testing web sites to check it with Safari. All the space characters seem to work fine, both in Safari 9.1.3, and in Safari 7.1.
我没有 Apple 设备,但我使用了几个跨浏览器测试网站来使用 Safari 进行检查。在 Safari 9.1.3 和 Safari 7.1 中,所有空格字符似乎都可以正常工作。
回答by Paul
I wanted to align boxes in a form and used  
in a span
using style="padding-left: 0.7em
before the input element. I then adjusted each em to align the boxes using 0.4em
, 0.85em
, 0.95em
and 1.3em
which all lined up against the input box that did not require any adjustment.
我想在表单中对齐框并 
在输入元素之前span
使用style="padding-left: 0.7em
。然后我调整每个 em 以使用0.4em
,对齐框0.85em
,0.95em
并且1.3em
所有这些框都与不需要任何调整的输入框对齐。