6

I haven't found any documentation yet, so I don't think it's doable. But it's worth asking.

Can I specify actual Text inside a style, within the stylesheet?

I have a few places that use the same text in the same div places. And instead of using javascript or retyping the same text in the divs, I was pondering if styles can have actual "text" inserted inside.

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

I might be pushing this one.

coffeemonitor
  • 12,780
  • 34
  • 99
  • 149
  • Related: [What are good uses of css "Content" property?](http://stackoverflow.com/questions/2435513/what-are-good-uses-of-css-content-property) – Richard JP Le Guen Aug 31 '11 at 17:04

4 Answers4

12

You're looking for the content property.

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

This property is used with the :before and :after pseudo-elements to generate content in a document.

So you could do something like...

.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"
}
Richard JP Le Guen
  • 28,364
  • 7
  • 89
  • 119
  • More about pseudo-elements than about the `content` property, but [Nicolas Gallagher has done some amazing stuff, creating pure CSS icons](http://nicolasgallagher.com/pure-css-gui-icons/demo/). Extremely impressive; extremely cool. – Richard JP Le Guen Aug 31 '11 at 17:03
7

you can use this approach with the :before and :after pseudo-elements

.someclass:after {
  content:"for example";
  color:#000;
}
kenwarner
  • 28,650
  • 28
  • 130
  • 173
2

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

.someclass:before{ 
    content:"for example";
}
Simon Arnold
  • 15,849
  • 7
  • 67
  • 85
0

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

$('.someclass').html("for example");
David Laberge
  • 15,435
  • 14
  • 53
  • 83