What are selectors in CSS?

Recommended Answers

All 2 Replies

They are the patterns you use to select elements eg:

p
{
    color: red;
}

This makes all paragraphs red - the "p" is the selector

Or:

.active
{
    border: 1px solid red;
}

The selector is ".active" which selects all elements with a class of active

Selectors help to select an element to which you want to apply a style. For example below is a simple style called as ‘intro” which applies red color to background of a HTML element.

    <style>
    .intro
    {
    background-color:red;
    }
    </style> 

To apply the above “intro” style to div we can use the “class” selector as shown in the below figure.

<div class="intro">
<p>My name is Shivprasad koirala.</p>
<p>I write interview questions.</p>
</div> 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.