开发者

What's the proper way to write a CSS selector with a class AND a pseudo class?

Simple Question: what's the proper way to write a CSS selector with a class AND a pseudo class?

For example:

a.someclass:active {
  top:1px;
}

or

a:active开发者_StackOverflow中文版.someclass {
  top:1px;
}

Which is correct? If possible, can you give me a source on this - such as a W3C reference? I tried to find it but alas I could not.


They are both correct, although the first one is more common.

Here's what's specified in the CSS grammar. You can see that the .class and :pseudo selectors are both allowed in the same places, along with #id and [attrib=val] selectors:

simple_selector
  : element_name [ HASH | class | attrib | pseudo ]*
  | [ HASH | class | attrib | pseudo ]+
  ;
class
  : '.' IDENT
  ;
pseudo
  : ':' [ IDENT | FUNCTION S* [IDENT S*]? ')' ]
  ;


First one is Both are right

Selectors Level 3


Both should be ok, if I understand the documentation correctly:

Pseudo-classes are allowed in all sequences of simple selectors contained in a selector. Pseudo-classes are allowed anywhere in sequences of simple selectors, after the leading type selector or universal selector (possibly omitted).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜