directory

 

Id and class selectors

The id selector

The class selector


Id and class selectors

If you want to set CSS styles in HTML elements, you need to set the “ID” and “class” selectors in the elements.

 

The id selector

The ID selector can specify a specific style for HTML elements marked with a specific ID.

HTML elements use id attributes to set id selectors. CSS id selectors are defined as “#”.

The following style rules apply to the element attribute id= “para1” :

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

Do not start the ID attribute with a number. Ids that start with a number do not work in Mozilla/Firefox

 

The class selector

cla