Did CSS has second-letter pseudo element

久未见 提交于 2021-01-23 10:58:32

问题


I'm using a CSS style for a letter to change a color of a first second third letter.

like this:

.header .logo h1 > a:first-letter {
  color: #f91ea5;
}

but I don't know how to change a color of second and third letter it's don't have a second-letter element.


回答1:


I think, you cannot use pseudo elements as :second-letter or :third-letter. It's by design. But if it's realy necessary, then use JavaScript, for example: this or this.




回答2:


No, there is no selector for second or third letter, in Selectors Level 3 or even as planned in the Selectors Level 4 draft. (If there even will be such selectors, they will most probably follow the patter of :nth-child(...).)

What you can do is to wrap the letters in text-level containers, e.g.

<a ...>A<span class=second>C</span><span class=third>M</span>E</a>

Then you can use normal class selectors like .second.



来源:https://stackoverflow.com/questions/23189981/did-css-has-second-letter-pseudo-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!