# Field with padding is visible even when empty

**URL:** <https://forums.ankiweb.net/t/field-with-padding-is-visible-even-when-empty/50192>\
**Category:** Help\
**Created:** [October 2, 2024, 1:30pm UTC](https://forums.ankiweb.net/t/field-with-padding-is-visible-even-when-empty/50192 "2024-10-02T13:30:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![flipside555](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@flipside555](https://forums.ankiweb.net/u/flipside555)\
**Post date:** [October 2, 2024, 1:30pm UTC](https://forums.ankiweb.net/t/field-with-padding-is-visible-even-when-empty/50192/1 "2024-10-02T13:30:54Z")

</div>

I have some fields on my cards which are often empty. They have a background color. If they have padding, then the field is visible even when it’s empty. The top answer [here](https://stackoverflow.com/questions/1992822/remove-padding-for-an-empty-element) looks as though it should fix the problem but it doesn’t seem to work.

I tried working around it by nesting containers and using margin instead of padding. It worked but there was no top margin. In order to get a top margin, I had to add `overflow:auto`; Doing that had the same effect as padding; it caused the field to be visible when empty.

I looked at conditional generation, but as far as I could tell that’s for solving a different problem.

The `fill empty fields` option is unchecked.

The red block here is an empty field.

![image](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/3X/e/4/e40383dcc24e298f86ccd488f58a14cd38c54a18.png)

---

<div class="post-metadata">

**Author:** ![Danika\_Dakika](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/danika_dakika/32/17815_2.png) [@Danika\_Dakika](https://forums.ankiweb.net/u/Danika_Dakika)\
**Post date:** [October 2, 2024, 2:03pm UTC](https://forums.ankiweb.net/t/field-with-padding-is-visible-even-when-empty/50192/2 "2024-10-02T14:03:34Z")

</div>

> [@flipside555](#):
>
> I looked at conditional generation, but as far as I could tell that’s for solving a different problem.

[Conditional replacement](https://docs.ankiweb.net/templates/generation.html#conditional-replacement) should take care of this, so I don’t know why that wasn’t working for you.

You don’t say whether this formatting is on your template directly, or your template refers to a class on your Styling, but it should work the same either way. Anything inside a `{{#FieldX}}...{{/FieldX}}` (on your template) – whether text, image, or formatting – should be skipped when “FieldX” is empty. You should post the text of what you were trying, and perhaps we can help make that work.

---

<div class="post-metadata">

**Author:** ![flipside555](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@flipside555](https://forums.ankiweb.net/u/flipside555)\
**Post date:** [October 2, 2024, 2:32pm UTC](https://forums.ankiweb.net/t/field-with-padding-is-visible-even-when-empty/50192/3 "2024-10-02T14:32:07Z")

</div>

This is basically what I’m doing.

_Template_

```auto

<div class=myclass>
{{cloze:myfield}}
</div>

```

_Styling_

```auto
.myclass{
background: #F6F5F0;
padding: 20px;
}

```

---

<div class="post-metadata">

**Author:** ![Danika\_Dakika](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/danika_dakika/32/17815_2.png) [@Danika\_Dakika](https://forums.ankiweb.net/u/Danika_Dakika)\
**Post date:** [October 2, 2024, 3:00pm UTC](https://forums.ankiweb.net/t/field-with-padding-is-visible-even-when-empty/50192/4 "2024-10-02T15:00:02Z")

</div>

Cloze cards are a bit different – the card shouldn’t be created at all if the field doesn’t have a cloze marker (which it won’t if it’s empty). But you can also use conditional replacement based on which card/cloze number Anki is displaying. [Card Generation - Anki Manual](https://docs.ankiweb.net/templates/generation.html#cloze-templates)

Did you try conditional replacement and it didn’t work?

```auto
{{#myfield}}
<div class=myclass>
{{cloze:myfield}}
</div>
{{/myfield}}

```

---

<div class="post-metadata">

**Author:** ![flipside555](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@flipside555](https://forums.ankiweb.net/u/flipside555)\
**Post date:** [October 2, 2024, 3:09pm UTC](https://forums.ankiweb.net/t/field-with-padding-is-visible-even-when-empty/50192/5 "2024-10-02T15:09:58Z")

</div>

I tried this which didn’t work.

```auto
<div class="myclass">
{{#myfield}}
{{cloze:myfield}}
{{/myfield}}
</div>

```

```auto
.myclass:empty,
.myclass:blank {
  display: none;
}

```

---

<div class="post-metadata">

**Author:** ![Danika\_Dakika](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/danika_dakika/32/17815_2.png) [@Danika\_Dakika](https://forums.ankiweb.net/u/Danika_Dakika)\
**Post date:** [October 2, 2024, 4:45pm UTC](https://forums.ankiweb.net/t/field-with-padding-is-visible-even-when-empty/50192/6 "2024-10-02T16:45:39Z")

</div>

Do you see why? You put the class – which draws the box – _outside_ of the conditional. Then the class can see all of that stuff _inside_ the div tags – so it draws the box. Since the class doesn’t know anything about Anki syntax, it doesn’t know that they might or might not appear.

Try it the other way round, like I had it above.

---

<div class="post-metadata">

**Author:** ![flipside555](https://avatars.discourse-cdn.com/v4/letter/f/96bed5/32.png) [@flipside555](https://forums.ankiweb.net/u/flipside555)\
**Post date:** [October 3, 2024, 6:26pm UTC](https://forums.ankiweb.net/t/field-with-padding-is-visible-even-when-empty/50192/7 "2024-10-03T18:26:45Z")

</div>

That fixed it. Thanks a lot for your help.

---

<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:** [November 2, 2024, 6:27pm UTC](https://forums.ankiweb.net/t/field-with-padding-is-visible-even-when-empty/50192/8 "2024-11-02T18:27:18Z")

</div>

Closed on November 2, 2024, 6:27pm UTC

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