开发者

CSS - adding text to the styles in stylesheet

I haven't found any documentation yet, so I don't think it's开发者_如何学Go 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.


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


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

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


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

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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜