CSS 首字下沉在 IE9 中使用 em 填充错误定位
这是一个比其他任何问题都更有趣的问题,因为我已经设法解决了它,但并不是一个我觉得完全令人满意的解决方案。我宁愿知道问题发生的原因,以便更好地理解它。
我有几个段落的第一个字母是首字母大写,使用 CSS3 伪选择器。这在 FF、Opera 和 Safari 中显示良好,但在 IE9 中则不然。问题是我使用 em 单位作为填充来定位字母。如果我将它们更改为 px,则该字母在所有浏览器中都可以正常显示;但我不高兴在我的文本上混合 px 和 em 。我认为这与 IE9 渲染 em 单位的方式有关。
p {
margin:0 0 1.5em 0;
text-align:justify;
font:1em/1.5 Georgia, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", serif;
}
.post-content p:first-child:first-letter {
float:left;
color:#444;
font-size:3.3em;
padding:0.1em 0.1em 0 0;
line-height:0.7em;
text-shadow:2px 2px 0 #dadada;
}
<section class="post-content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet mi ut erat dapibus varius. Cras aliquet augue eget ipsum posuere a mattis quam gravida. Proin pretium rhoncus mi, nec dapibus odio iaculis id. Aenean mattis, nulla eu hendrerit fermentum, urna tellus tristique mauris, eu dignissim quam arcu ut nisi.</p>
</section>
我在这里做了一个 JSFiddle: http://jsfiddle.net/C5zsv/
This is more of an intriguing problem than anything else since I have managed to solve it, but not with a solution that I find entirely satisfying. I'd rather know why the problem occurs to better understand it.
I have several paragraphs with drop-caps on the first letters using CSS3 pseudo-selectors. This displays fine in FF, Opera and Safari but not IE9. The problem is the em units I'm using as padding to position the letter. If I change these to px the letter displays fine in all browsers; BUT I'm not happy mixing px and em on my text. I assume this has something to do with how IE9 renders em units.
p {
margin:0 0 1.5em 0;
text-align:justify;
font:1em/1.5 Georgia, Palatino, "Palatino Linotype", "Palatino LT STD", "Book Antiqua", serif;
}
.post-content p:first-child:first-letter {
float:left;
color:#444;
font-size:3.3em;
padding:0.1em 0.1em 0 0;
line-height:0.7em;
text-shadow:2px 2px 0 #dadada;
}
<section class="post-content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sit amet mi ut erat dapibus varius. Cras aliquet augue eget ipsum posuere a mattis quam gravida. Proin pretium rhoncus mi, nec dapibus odio iaculis id. Aenean mattis, nulla eu hendrerit fermentum, urna tellus tristique mauris, eu dignissim quam arcu ut nisi.</p>
</section>
I've made a JSFiddle here: http://jsfiddle.net/C5zsv/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这个问题对我来说就像一个美妙的黑匣子谜题,所以我试图收集一些证据来支持任何答案。事实证明,各种浏览器对
em
和:first-letter
的组合的呈现方式截然不同。首先,这是我用来测试这个的代码(问题小提琴的一个分支):
和CSS:
查看 the new fiddle
在各种浏览器中如何呈现:
基本上这个问题的答案(或者至少是底线,没有双关语)似乎是:混合
em
和first- letter
让您的网站受浏览器和字体系列的支配。孩子们,他们是不仁慈的。这种“怜悯”还有一些有趣的功能:
来自 w3.org 的信息
在 CSS3-linebox 模块中,有一些关于 基线对齐< /a> 这似乎与这些问题相关。可能需要阅读一下才能了解其状态(或者也许这里有人可以添加它?)。
Right, this question felt like a wonderful black box puzzle to me, so I tried to gather some evidence to support any answers. Turns out various browsers render the combination of
em
and:first-letter
quite differently.First up, here's the code I used to test this (a fork of the question's fiddle):
And the CSS:
Check out the new fiddle
How this renders in various browsers:
Basically the answer to this SO question (or at least bottom line, no pun intended) seems to be: mixing
em
andfirst-letter
leaves your site at the mercy of the browser and the font-family. And boy, are the not merciful.This "mercy" has a few interesting features as well:
Info from w3.org
In the CSS3-linebox module there is some info on baseline alignment that seems relevant to these issues. May have to read on a bit to see what the status is on that (or perhaps someone here can add it?).