Maxlight Maxlight - 3 months ago 11
CSS Question

How do I apply class to img element that is under a element

I have this piece code:



.someclass > img {
width: 143px;
height: 143px;
}

<div class="someclass">
<img src="http://i.imgur.com/wT188Qs.jpg">
<a href="#">
<img src="http://i.imgur.com/wT188Qs.jpg">
</a>





First image gets resized to 143px, but the second one does not. I thought that all img elements under someclass would get styled, but it seems if there is another element between them then they don't get styled.

What css can I write to get it working?

https://jsfiddle.net/8h0sh5jf/

Answer

if you use

.someclass img{
    width: 143px; 
    height:143px;
}

it will apply to all images inside the .someclass div

if you want just the ones wrapped in an a tags inside the someclass div use

.someclass a img{
    width: 143px; 
    height:143px;
}