CSS - adding text to styles in a stylesheet

I haven't found any documentation yet, so I don't think this is possible. But it is worth asking.

Is it possible to specify the actual text inside the style within the stylesheet?

I have several places that use the same text in the same div places. And instead of using javascript or retyping the same text in a div, I wondered if the styles could have the actual “text” inserted inside.

.someclass {
  text:"for example";  /* this is how I'd imagine it, IF it were possible */
  color:#000;
}

I could click this one.

+5
source share
4 answers

You are looking for the content property .

Unfortunately, it can only be used with pseudo-elements.

: before : after .

, - ...

.someclass:before {
   content: "This text will be added at the beginning of the element"
}
.someclass:after {
   content: "This text will be added at the end of the element"
}
+9

- :before :after

.someclass:after {
  content:"for example";
  color:#000;
}
+5

Use before or after the pseudo-class to achieve this: For example:

.someclass:before{ 
    content:"for example";
}
+1
source

I do not think that this could be done in CSS. But in jQuery it will look like this:

$('.someclass').html("for example");
0
source

All Articles