The meaning of “replaced content” and why it’s ignored by CSS

I was catching up on Sime Vidas’ Web Platform News and came up on a post that explains why the ::before and ::after pseudo-elements do not work with form inputs and images. The term “replaced content” was sprinkled in and, while Sime does a great job illustrating its effect on CSS, I was still confused […]

The post The meaning of “replaced content” and why it’s ignored by CSS appeared first on Geoff Graham.


This content originally appeared on Geoff Graham and was authored by Geoff Graham

I was catching up on Sime Vidas’ Web Platform News and came up on a post that explains why the ::before and ::after pseudo-elements do not work with form inputs and images.

The term “replaced content” was sprinkled in and, while Sime does a great job illustrating its effect on CSS, I was still confused by what it actually means.

So I looked it up and the spec has this to say:

An element whose content is outside the scope of the CSS formatting model, such as an image or embedded document. For example, the content of the HTML <a href="https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element">img</a> element is often replaced by the image that its <a href="https://html.spec.whatwg.org/multipage/embedded-content.html#attr-img-src">src</a> attribute designates.

Cool. If I understand correctly, the idea is that an element is considered “replaced” if the thing that renders isn’t the element itself, but what an attribute in it refers to. The example the spec uses is an img element. The element itself has an intrinsic width and height (defined by those attributes) that give it physical dimensions, but what gets rendered is the file specified in the src attribute. That means the element is replaced by that image file.

And replaced elements replace all their contents. That includes pseudo-elements which will not be considered in the CSS formatting model.

I’m still not exactly sure how that applies to form inputs but it might be in this line in the spec:

User agents may consider a replaced element to not have any intrinsic dimensions if it is believed that those dimensions could leak sensitive information to a third party.

That would explain Sime’s point that Both Chrome and Safari actually support ::before and ::after on some form inputs, like checkboxes and radio buttons, but not others, like text and numeric inputs.

Source / Spec

The post The meaning of “replaced content” and why it’s ignored by CSS appeared first on Geoff Graham.


This content originally appeared on Geoff Graham and was authored by Geoff Graham


Print Share Comment Cite Upload Translate Updates
APA

Geoff Graham | Sciencx (2020-09-08T17:35:15+00:00) The meaning of “replaced content” and why it’s ignored by CSS. Retrieved from https://www.scien.cx/2020/09/08/the-meaning-of-replaced-content-and-why-its-ignored-by-css/

MLA
" » The meaning of “replaced content” and why it’s ignored by CSS." Geoff Graham | Sciencx - Tuesday September 8, 2020, https://www.scien.cx/2020/09/08/the-meaning-of-replaced-content-and-why-its-ignored-by-css/
HARVARD
Geoff Graham | Sciencx Tuesday September 8, 2020 » The meaning of “replaced content” and why it’s ignored by CSS., viewed ,<https://www.scien.cx/2020/09/08/the-meaning-of-replaced-content-and-why-its-ignored-by-css/>
VANCOUVER
Geoff Graham | Sciencx - » The meaning of “replaced content” and why it’s ignored by CSS. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/09/08/the-meaning-of-replaced-content-and-why-its-ignored-by-css/
CHICAGO
" » The meaning of “replaced content” and why it’s ignored by CSS." Geoff Graham | Sciencx - Accessed . https://www.scien.cx/2020/09/08/the-meaning-of-replaced-content-and-why-its-ignored-by-css/
IEEE
" » The meaning of “replaced content” and why it’s ignored by CSS." Geoff Graham | Sciencx [Online]. Available: https://www.scien.cx/2020/09/08/the-meaning-of-replaced-content-and-why-its-ignored-by-css/. [Accessed: ]
rf:citation
» The meaning of “replaced content” and why it’s ignored by CSS | Geoff Graham | Sciencx | https://www.scien.cx/2020/09/08/the-meaning-of-replaced-content-and-why-its-ignored-by-css/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.