I am wondering whether the :before
and :after
pseudo-elements can inherit the height from parent using the inherit
value, without the actual element doing so?
CSS ::before and ::after pseudo-elements allow you to insert “content” before and after any non-replaced element (e.g. they work on a <div> but not an <input> ). This effectively allows you to show something on a web page that might not be present in the HTML content.
In CSS, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property. It is inline by default.
In CSS2. 1, an element can only have at most one of any kind of pseudo-element at any time. (This means an element can have both a :before and an :after pseudo-element — it just cannot have more than one of each kind.)
There are no special rules around combining pseudo-classes and pseudo-elements, besides the one rule that says there can only be one pseudo-element per complex selector and it must appear at the very end.
No. The only way that pseudo-elements can inherit values from the parent of their generating element is when the generating element itself is also inheriting from its parent.
This is because inheritance occurs from a parent to a child, one level at a time. For inheritance to work across several levels of descendants, every descendant must inherit.
As an example, consider the following HTML:
<div class="parent"> <div class="child"> </div> </div>
With the following CSS:
.parent { width: 100px; height: 100px; } .parent > .child:before, .parent > .child:after { content: ''; position: absolute; width: inherit; height: inherit; }
This will not work because even though the pseudo-elements have values of inherit
, the element generating them, that is, .parent > .child
, does not inherit from .parent
. Instead, they inherit the default value of auto
for both properties.
In order for this to work you will need to have .parent > .child
inherit as well:
.parent { width: 100px; height: 100px; } .parent > .child { width: inherit; height: inherit; } .parent > .child:before, .parent > .child:after { content: ''; position: absolute; width: inherit; height: inherit; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With