Steven Spielberg
Steven Spielberg

Reputation:

how to select image using css

This is my html:

<div id="content">
    <img src="myimg.png" alt="this image need to select"/>
    <div  class="some">
        <img src="another.png" alt="this is not need  to select"/>
    </div>   
</div>

I want to select all image which are inside id content but not which are inside the div or span of content div i.e. select all image directly inside the content div and not the ones that are inside the div or span of content div.

Any thoughts?

Upvotes: 0

Views: 18645

Answers (3)

Sarfraz
Sarfraz

Reputation: 382696

You can use > to select direct/immediate children of the div like this:

#content > img{
  // target direct children
}

Check out the demo here (the desired image is given blue border)

More Info:

Upvotes: 10

shankhan
shankhan

Reputation: 6571

you can write

#content > img {

}

Upvotes: 0

Madhur Ahuja
Madhur Ahuja

Reputation: 22681

Not an expert, but this should work -> div#content > img

Upvotes: 0

Related Questions