CSS stands for cascading style sheets.It is used for styling the web pages like giving color to text, changing font-size, giving background-color,height, width etc.The simplified version of what happens when a browser loads a webpage is defined below:
- The browser loads the HTML document.
- It converts the HTML into DOM.
- The browser then fetches the resources linked to the HTML document like images, videos amd linked CSS.JavaScript is handled a bit later.
- The browder parses the fetched CSS and sorts the different rulus by their selector types into different "buckets" eg element,class etc.Based on the rules, the browser works out which rules shoulb be applied to which nodes of the DOM and attaches styles to them as required.
- The tree is laid out in the structure it should appear in, after the rules have been applied.
- The visual page is displayed on the screen ,this stage is called painting.
CSS syntax:
A CSS rule-set consists of a selector and a declaration block which define the properties to be applied to the nodes.
p{
font-size:30px;
color:blue;
}
Here, "p" is the selector which targets the paragraph node of the DOM and the properties inside it defines the styling of the node.
CSS selctors:
The CSS selectors have been classified into five main categories:
- Simple selctors.
- Combination Selectors.
- Pseudo-class selectors.
- Pseudo-elements selectors.
- Attribute selectors.
Top comments (0)