Sunday 16 October 2022

CSS Selectors

 CSS Selectors

In CSS, selectors are patterns used to select the element(s) you want to style

There are 3 different types of CSS selectors

1.Element

2.Class

3.ID

We will see in details below,

1.Element

  The element selector selects HTML elements based on the element name.

Example:

p--Selects all <p> elements

<p>My first CSS tutorials</p>

p{

    text-align: center;

    color: red;

}

Here, all the paragraph will have text aligned in Center with color red.


2.Class

The class selector selected HTML elements based on the specific class attributes.

This will have (.) period followed by class name.


<p class="center">My first CSS tutorials.</p> 

.center {

      text-align: center;

      color: red;

}

Here, all the element with class="center" will text aligned in Center with color red.


3.ID

ID selector uses the ID attribute of an HTML element to select a specific element.

ID selector is unique across the page, it should be used to select one unique element.

Write (#) character followed by id of the element.


<p id="para_1">My first CSS tutorials.</p>

#para_1 {

      text-align: center;

      color: red;

Here, the specific id (para_1) element will be render on to the page with text aligned in Center and color red.

CSS Selectors

  CSS Selectors In CSS, selectors are patterns used to select the element(s) you want to style There are 3 different types of CSS selectors ...