Combining Pseudo-selectors in CSS?

天大地大妈咪最大 提交于 2019-12-01 16:44:10

If you're talking about pseudo-classes, then yes, you can combine them in any order.

Except in this case, ::selection is not a pseudo-class, it's a pseudo-element that's not part of CSS1 or CSS2, or any current spec for that matter. And this is where the term "pseudo-selector" falls short, because they're two completely different things.

The correct syntax is a single colon for :hover and double colons for ::selection, and unlike pseudo-classes, pseudo-elements must always come last:

.abc:hover::selection{color:red}

And even then, because of the way ::selection works (or doesn't), it's not guaranteed to actually have an effect in browsers.

 .container:nth-last-child(2):not(:first-child) {
    background-color: red;
 }

Yes, it is the recommended way to do it, see the w3c about pseudo classes : http://www.w3.org/TR/CSS2/selector.html#dynamic-pseudo-classes

EDIT : as BoltClock pointed out, this link if for CSS2, this is the document for CSS3 : http://www.w3.org/TR/css3-selectors/#the-user-action-pseudo-classes-hover-act

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