CSS :: before无效:: first-letter

Mai*_*ret 5 html css

Html代码:

<h1>Example title</h1>
Run Code Online (Sandbox Code Playgroud)

CSS:

h1::first-letter{
    display:none;
}
h1::before{
    content: url(http://icons.iconarchive.com/icons/ariil/alphabet/32/Letter-E-icon.png);
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:为什么::之前是杀人::第一封信规则?这里发生了什么?如果:: before被删除,:: first-letter工作正常.

是否有任何替代方法可以在不更改html的情况下定位此示例中的第一个字母?

http://jsfiddle.net/Borachio/kvaxmhth/

Moo*_*man 5

规格:

规则之后p::before {content: "Note: "},选择器 p::first-letter matches the "N" of "Note".

另请注意,display属性:first-letter:first-line伪元素无效.再次,从规范:

此规范的未来版本可允许此伪元素应用于更多显示类型.

这是预期的行为.

解决方法:

HTML:

<div><h1>Example title</h1></div>
Run Code Online (Sandbox Code Playgroud)

和CSS:

h1{
    display: inline-block;
}
h1::first-letter{
    font-size: 0px;
}
div::before{
    content: url(http://icons.iconarchive.com/icons/ariil/alphabet/32/Letter-E-icon.png);
}
Run Code Online (Sandbox Code Playgroud)

演示:http://jsfiddle.net/kvaxmhth/3/

  • 图像是图像,而不是字母. (2认同)