Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How the CSS content attribute works?

Tags:

css

Can some one explain how the content attribute internally work in the browser. Does it create a new node in the DOM even it is not displayed in the webInspector. And will it have the same influences of memory consumption like a real DOM node?

like image 956
Andreas Köberle Avatar asked Jan 21 '13 20:01

Andreas Köberle


People also ask

What is the content attribute in CSS?

The content CSS property replaces an element with a generated value. Objects inserted using the content property are anonymous replaced elements.

What does the content attribute do in HTML?

The content attribute in HTML is used to display the value with the name or http-equiv. It is associated with the <meta> element. The content attribute of the <meta> element is used to set the meta information in an HTML document. This can be the information for the description or the keywords, for name attribute.

How do you attribute in CSS?

CSS [attribute^="value"] Selector The [attribute^="value"] selector is used to select elements with the specified attribute, whose value starts with the specified value. The following example selects all elements with a class attribute value that starts with "top": Note: The value does not have to be a whole word!

How get value of data attribute in CSS?

The attr() CSS function is used to retrieve the value of an attribute of the selected element and use it in the stylesheet. It can also be used on pseudo-elements, in which case the value of the attribute on the pseudo-element's originating element is returned.


2 Answers

I found this on CSS 2.1 spec

Generated content does not alter the document tree. In particular, it is not fed back to the document language processor (e.g., for reparsing).

like image 145
Hieu Le Avatar answered Oct 10 '22 21:10

Hieu Le


From the W3C:

This property (content) is used with the :before and :after pseudo-elements to generate content in a document. Generated content does not alter the document tree. In particular, it is not fed back to the document language processor (e.g., for reparsing).

Also, according to MDN:

Objects inserted using the content property are anonymous replaced elements. In CSS, a replaced element is an element whose representation is outside the scope of CSS. These are kind of external objects whose representation is independant of the CSS. Typical replaced elements are <image>, <object>, <video> or forms element like <textarea>, <input>. Some elements, like <audio> or <canvas> are replaced elements only in specific cases. Object inserted using the CSS content properties are anonymous replaced elements. CSS handled replaced elements specifically in some cases, like when calculating margins and some auto values. Note that some replaced elements, but not all, have intrinsic dimensions or a defined baseline, which is used by some CSS properties like vertical-align.

like image 40
j08691 Avatar answered Oct 10 '22 20:10

j08691