# Why does the class definition not affect images?

**URL:** <https://forums.ankiweb.net/t/why-does-the-class-definition-not-affect-images/25514>\
**Category:** Card Design\
**Created:** [December 19, 2022, 6:52pm UTC](https://forums.ankiweb.net/t/why-does-the-class-definition-not-affect-images/25514 "2022-12-19T18:52:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![noty](https://avatars.discourse-cdn.com/v4/letter/n/7ba0ec/32.png) [@noty](https://forums.ankiweb.net/u/noty)\
**Post date:** [December 19, 2022, 6:52pm UTC](https://forums.ankiweb.net/t/why-does-the-class-definition-not-affect-images/25514/1 "2022-12-19T18:52:38Z")

</div>

Why is this code not working for me?

```auto
img.daf{
max-width: 20px;
max-height: 20px;
}

```

---

<div class="post-metadata">

**Author:** ![jcznk](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jcznk/32/15215_2.png) [@jcznk](https://forums.ankiweb.net/u/jcznk)\
**Post date:** [December 19, 2022, 7:14pm UTC](https://forums.ankiweb.net/t/why-does-the-class-definition-not-affect-images/25514/2 "2022-12-19T19:14:19Z")

</div>

```auto
.daf img {
max-width: 20px;
max-height: 20px;
}

```

This should work

> [@noty](#):
>
> Why is this code not working for me?
> 
> ```auto
> img.daf{
> max-width: 20px;
> max-height: 20px;
> }
> 
> ```

I think it is because when you use `img.daf` as a selector (with no spaces between img and .daf), the CSS tries to match all elements that are images **and** also have the class daf.  
[https://www.w3schools.com/cssref/css\_selectors.php](https://www.w3schools.com/cssref/css_selectors.php)

But in this code:

```auto
<div class="daf">
 <img src="foo.jpg">
</div>

```

the element with the class daf is not the image, rather the div in which it is contained.  
Since the document contains no element that is both an image and has the class daf, the styling cannot be applied.

In the following example `img.daf` would instead work:

```auto
<img src="foo.jpg" class="daf">

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [January 18, 2023, 7:14pm UTC](https://forums.ankiweb.net/t/why-does-the-class-definition-not-affect-images/25514/3 "2023-01-18T19:14:23Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
