Tsury
Tsury

Reputation: 739

CSS - Targeting a specific element

I have this HTML:

<div class="B">
   blah
   blah
   blah
</div>

<section class="A">
    <div class="B"/> <!-- THIS -->
    <div/>
</section>

How can I target the div with the B class inside the section, and only it?

Upvotes: 1

Views: 58

Answers (2)

Lal
Lal

Reputation: 14810

You can select it like this

.A>.B{

}

This is known as CSS element>element Selector

The syntax is as follows

element > element {
    css declarations;
}

you can see an example here..

Upvotes: 1

ianaya89
ianaya89

Reputation: 4233

You should write :

section.A div.B {
}

If you want target just one element consider use id instead class.

Upvotes: 0

Related Questions