When it comes to changing the content on a page, CSS is not the tool for the job – JavaScript is what you need. However, there is a workaround using the :before
pseudo-element in CSS to create a 'fake' element and add content to it using the content
rule.
.runtime:before{
content: "Important Generated Content";
font-weight: bold;
}
Some individuals may encounter challenges with this approach as CSS was originally designed to style elements, not insert text. While CSS provides a more convenient solution compared to JavaScript, there is a significant drawback – users relying on assistive technologies may experience difficulties as discussed in this blog post, as the generated content within pseudo-elements will not be accessible.
An alternative method involves utilizing JavaScript to generate the label. The following example demonstrates how to add a <p>
element above all elements with the class .important
.
View on jsFiddle
HTML
<div class="important">I am very important</div>
<div>I am not</div>
<div class="important">I am very important</div>
jQuery
$(document).ready(function () {
$('.important').before('<div class="important-notice">Important!</div>');
});