i

Learn HTML and CSS in 10 Days

Getting to Know CSS :The Cascade

CSS offers us the ability to add designs and layout inside our web page. One can also share those layouts with different elements and pages of the website. Before unlocking all features, there is a couple of different languages we should completely comprehend.

As we begin, we need to understand how the styles get processed. One of the most important thing that we need to learn is about the working procedure of different selectors and how their different order may affect the style of the page. We also need to have a good idea about a couple of property value like that of color and length.

Let's start with CSS and see what is going to happen.

The Cascade

Here we are going to start the study by knowing the rendering process of the styles. For this, we will be looking at the cascade and learning a couple of examples regarding it. In the CSS file all styles cascade from top to bottom.

Let’s take an example here

p {

  background: orange;

  font-size: 24px;

}

p {

  background: green;

}

In the above code, at first, we have selected all the paragraph on the web page and changed their background to orange and the font size to 24px. Towards the bottom, we select the paragraph again and changes the colour to green.

As the paragraph selector that has the background colour of green comes after the paragraph selector that has the background colour of orange, it will take precedence. Every paragraph will be appearing green. But the font size of the paragraph will be of 24 pixels.

Cascading Properties

The cascade property from top to bottom works well inside an individual selector. Let's take up an example of this.

p {

  background: orange;

  background: green;

}

In the above example, you can see that inside the paragraph element, we have given two backgrounds values one after the other, one says orange, and the other says green. As the green value of the background is after the orange one, the whole background for the paragraph will be green.

Thus we can see in the above examples that all styles cascade from top to bottom in our style sheet. But still, there are many places where the cascade property does not come into play. This situation only takes place when the web page uses different selectors, and the particularity of those selectors breaks the course. Let’s check them out.