0

Any idea why the not selector below for the image is not working?

I want the not selector prevent the picture from having 20% width. I am trying to select the class test which my image is a part of.

Codepen: https://codepen.io/anon/pen/gRNOgx

<style>
img:not(.test){
    width:20%;
}
</style>
<html>
<div class="test"><img src="http://i.imgur.com/pMKpE40.jpg"></div>
</html>
David Somekh
  • 795
  • 3
  • 12
  • 33

1 Answers1

2

The selector matches an img element so long as it is not a member of the test class.

You have an <img> and it has no class attribute at all.

The <div> is a member of test, the <img> is not.

:not(.test) > img would not match that <img>, but it might not cover all your use cases.

CSS has no way to say "Element has no ancestor which matches a selector".

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335