We have learned about various types of selectors in preceding
lessons, now we shall examine the precedence rules that govern the
selectors. It is important to understand which rule will be given
precedence if two or more rules govern the same element. Based on these
rules, the browser will determine what styles to apply to a given HTML
element. Basically there are three rules, the sequential rule, the
specificity rule and the important rule.
Sibling Selector in CSS
We have learned about child and descendent selectors in previous lesson. In this lesson, we shall learn about another type of selector which also resembles members of a family, it is called sibling selector.
There are two types of sibling selectors, they are
The output
Sibling Selector in CSS
There are two types of sibling selectors, they are
8.1 Sequential Rule
The rule applies when two identical element are having different set of CSS properties, the latter will take precedent over the first. Let’s examine the following example:Example 8.1
We have learned about child and descendent selectors in previous lesson. In this lesson, we shall learn about another type of selector which also resembles members of a family, it is called sibling selector.
There are two types of sibling selectors, they are
adjacent sibling selector
andgeneral sibling selector
We have learned about child and descendent selectors in previous
lesson. In this lesson, we shall learn about another type of selector
which also resembles members of a family, it is called sibling selector.
There are two types of sibling selectors, they are
There are two types of sibling selectors, they are
adjacent sibling selector
andgeneral sibling selector
*Notice that the CSS rules of the second selector h2 applies.
8.2 Specificity Rule
Among the CSS selectors, some are more specific than others. If one particular selector is more specific than the other selectors, the CSS style rules of the more specific selector shall applies. Let’s examine the following example:Example 8.2
We have learned about child and descendent
selectors in previous lesson. In this lesson, we shall learn about
another type of selector which also resembles members of a family, it is
called sibling selector.
There are two types of sibling selectors, they are
adjacent sibling selector
andgeneral sibling selector
The Output
We
have learned about child and descendent selectors in previous lesson. In
this lesson, we shall learn about another type of selector which also
resembles members of a family, it is called sibling selector.
There are two types of sibling selectors, they are
adjacent sibling selector
andgeneral sibling selector
8.3 Important Rule
The important rule applies when you add !important after a property value. The !important keyword indicates that this selector should be given the top precedence over the other selectors. Let’s examine the following example:Example 8.3
We have learned about child and descendent
selectors in previous lesson. In this lesson, we shall learn about
another type of selector which also resembles members of a family, it is
called sibling selector.
There are two types of sibling selectors, they are
adjacent sibling selector
andgeneral sibling selector
The output
We
have learned about child and descendent selectors in previous lesson.
In this lesson, we shall learn about another type of selector which also
resembles members of a family, it is called sibling selector.
There are two types of sibling selectors, they are
0 Comments
Good day precious one, We love you more than anything.