css – p :: first-letter和p :: first-letter之间有什么区别?

前端之家收集整理的这篇文章主要介绍了css – p :: first-letter和p :: first-letter之间有什么区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > What does a space mean in a CSS selector? i.e. What is the difference between .classA.classB and .classA .classB?2个
p :: first-letter和p :: first-letter有什么区别?

p :: first-letter可以成功选择段落中的第一个字母,但p :: first-letter不能.

解决方法

选择器p :: first-letter选择p中的第一个字母,而p :: first-letter选择p的子元素中的第一个字母.

p :: first-letter相当于p * :: first-letter.以下是specs所说的内容

If a universal selector represented by * (i.e. without a namespace prefix) is not the only component of a sequence of simple selectors selectors or is immediately followed by a pseudo-element,then the * may be omitted and the universal selector’s presence implied.

注意:尽管选择器(p :: first-letter)本身指向所有子元素中的第一个字母,但:: first-letter选择器仅适用于块或内联块元素,因此不适用于跨度除非它的显示修改.

p ::first-letter {
  color: red;
}
p::first-letter {
  color: blue;
}

span{
  display: inline-block;
}
<p>Some text <span>inside a span</span> and <span>inside this span too</span>
</p>

猜你在找的CSS相关文章