Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeated Pseudo-Class Selectors

I noticed in the Bootstrap CSS file:

 input:focus:invalid:focus,
 textarea:focus:invalid:focus,
 select:focus:invalid:focus {
   border-color: #e9322d;
   -webkit-box-shadow: 0 0 6px #f8b9b7;
      -moz-box-shadow: 0 0 6px #f8b9b7;
           box-shadow: 0 0 6px #f8b9b7;
 s}

It appears that :focus is specified twice for input, textarea, and select; does this have a particular function?

like image 240
cardinal19821 Avatar asked Aug 27 '13 20:08

cardinal19821


People also ask

Can you use multiple pseudo class selectors with an element?

You can combine several CSS pseudo-elements for one element. However, you cannot use CSS ::after two times or ::before two times. In the example below, the first letter of <div> is green and has x-large font size.

Can you have multiple pseudo-classes?

Pseudo-classes are allowed anywhere in selectors while pseudo-elements may only be appended after the last simple selector of the selector. This means your syntax is correct according to CSS2. 1 and CSS3 as well, i.e. IE8 still sucks ;) Can I write element:hover:disable {} multiple pseudo-classes ?

What are pseudo class selectors?

What is a pseudo-class? A pseudo-class is a selector that selects elements that are in a specific state, e.g. they are the first element of their type, or they are being hovered over by the mouse pointer.

Can you chain pseudo selectors?

You can still chain pseudoselectors. For example, a:focus:hover works just fine to apply styles only if the element is focused AND hovered. See this link for a demonstration. It works fine (in Chrome, at least); click in the demo area, press tab to focus the link, then hover it to see it become bolded.


1 Answers

This increases the css selector's specificity.

Here is the relevant quote in the css specs:

Note: Repeated occurrences of the same simple selector are allowed and do increase specificity.

So, in this particular case, input:focus:invalid:focus will have precedence over input:focus:invalid.

Here is a simpler example demonstrating the increase in css specificity with repeated occurences:

css

span.color.color {
    color: green;
}

span.color {
    color: yellow;
}

html

<span class="color">This will be green.</span>
like image 76
edsioufi Avatar answered Oct 06 '22 15:10

edsioufi