CSS: Child combinator selector & :first-child?

Angenteri

New Member
I have a \[code\]div\[/code\] with some other \[code\]div\[/code\]s, some paragraphs and some images in it. It basically looks like this:\[code\]<div id="parent"> <div> This image is inside a div. <img src="http://www.placehold.it/100" alt="" /> </div> <p> And this inside a paragraph. <img src="http://www.placehold.it/100" alt="" /> </p> <img src="http://www.placehold.it/100" alt="" /> <img src="http://www.placehold.it/100" alt="" /></div>\[/code\]Now I only want to select the images that aren't nested inside another \[code\]div\[/code\] or \[code\]p\[/code\]. I am doing this using the child combinator selector:\[code\]#parent > img { border: 1px solid red;}\[/code\]This works, but now I only want to select the first, non-nested image. I tried it like this, but without any result:\[code\]#parent > img:first-child { border: 1px solid blue;}\[/code\]http://jsfiddle.net/vF2DU/How do I do it? Is there a way without adding a class or id like \[code\]#first\[/code\]?
 
Back
Top