AsegGasiaBlog

CSS Part 4

CSS Selector

CSS Element

The element selector selects elements based on the element name. You can select all <p> elements on a page like this: (all <p> elements will be center-aligned, with a red text color)

Example :


p{
    text-align: center;
    color: red;
}


 ID Selector
  • The id selector uses the id attribute of an HTML element to select a specific element.
  • An id should be unique within a page, so the id selector is used if you want to select a single, unique element.
  • To select an element with a specific id, write a hash character, followed by the id of the element.
  • The style rule below will be applied to the HTML element with id="para1":

Example :


#para1{
    text-align: center;
    color: red;
}



 


Popular Posts