empty pseudo. doubt regarding padding inherit

I'm testing with the :empty pseudo and tried giving it padding: inherit, it works the same as padding: 0. where is this padding being inherited from? I'm not using any resets https://codepen.io/kaedaDante/pen/BaxwMjx
5 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
MarkBoots
MarkBoots3y ago
in this case div.error:empty inherit looks at it's parent div. That doesnt have a padding set, so it will default to zero
<div> /*has no padding set */
<div class="error"></div> /*empty, inherit looks at parent div */
</div>
<div> /*has no padding set */
<div class="error"></div> /*empty, inherit looks at parent div */
</div>
Instead of removing the padding from an empty error, you could just only style the .error when it is :not(:empty)
.error:not(:empty) {
background: tomato;
padding: 0.5em 0.75em;
}
.error:not(:empty) {
background: tomato;
padding: 0.5em 0.75em;
}
∂αηтє
∂αηтєOP3y ago
although i haven't set explicitly set a padding, there is a default padding/margin right? or will it only inherit if i set a padding/margin by myself?
MarkBoots
MarkBoots3y ago
no, divs have no default paddings/margins
∂αηтє
∂αηтєOP3y ago
oh, in that case, this makes sense thanks for this!
Want results from more Discord servers?
Add your server