Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - adding text to the styles in stylesheet

Tags:

css

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.

like image 583
coffeemonitor Avatar asked Aug 31 '11 16:08

coffeemonitor


3 Answers

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"
}
like image 160
Richard JP Le Guen Avatar answered Sep 23 '22 22:09

Richard JP Le Guen


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

.someclass:after {
  content:"for example";
  color:#000;
}
like image 23
kenwarner Avatar answered Sep 23 '22 22:09

kenwarner


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

.someclass:before{ 
    content:"for example";
}
like image 24
Simon Arnold Avatar answered Sep 24 '22 22:09

Simon Arnold