coffeemonitor
coffeemonitor

Reputation: 13120

CSS - adding text to the styles in stylesheet

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.

Upvotes: 6

Views: 20389

Answers (4)

Simon Arnold
Simon Arnold

Reputation: 16157

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

.someclass:before{ 
    content:"for example";
}

Upvotes: 2

David Laberge
David Laberge

Reputation: 16031

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

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

Upvotes: 0

Richard JP Le Guen
Richard JP Le Guen

Reputation: 28753

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"
}

Upvotes: 12

kenwarner
kenwarner

Reputation: 29120

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

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

Upvotes: 7

Related Questions