DEV Community

M Ramavel
M Ramavel

Posted on

CSS Selectors

CSS id Selector

The id selector uses the id attribute of an HTML element to select a specific element.
To select an element with a specific id, write a hash (#) character, followed by the id of the element.

Example:

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

CSS Class selector

The class selector selects HTML elements with a specific class attribute.

To select elements with a specific class, write a period (.) character, followed by the class name

Ex:

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

Child combinator (>)

Ex:
div>p

Selects every

element that are direct children of a <div> element

**

Descendant combinator(single space)

Ex:
Selector ul l:

Selects all

elements inside

elements

Top comments (0)