Questions tagged [css-content]

CSS Generated Content allows us to insert and move content around a document. We can use this to create footnotes, endnotes, and section notes, as well as counters and strings, which can be used for running headers and footers, section numbering, and lists.

CSS Generated content, automatic numbering, and lists

CSS Generated Content allows us to insert and move content around a document. We can use this to create footnotes, endnotes, and section notes, as well as counters and strings, which can be used for running headers and footers, section numbering, and lists.

Authors specify the style and location of generated content with the :before and :after pseudo-elements. As their names indicate, the :before and :after pseudo-elements specify the location of content before and after an element's document tree content. The content property, in conjunction with these pseudo-elements, specifies what is inserted.

For example, the following rule inserts the string "Note: " before the content of every P element whose "class" attribute has the value "note":

p.note:before {
    content: "Note: ";
}

Examples

/* Keywords that cannot be combined with other values */
content: normal;
content: none;

/* <url> value */
content: url("http://www.example.com/test.png");

/* <image> value */
content: linear-gradient(#e66465, #9198e5);

/* values below can only be applied to generated content using ::before and ::after */

/* <string> value */ 
content: "prefix";

/* <counter> values */
content: counter(chapter_counter);
content: counters(section_counter, ".");

/* attr() value linked to the HTML attribute value */
content: attr(value string);

/* Language- and position-dependent keywords */
content: open-quote;
content: close-quote;
content: no-open-quote;
content: no-close-quote;

/* Except for normal and none, several values
   can be used simultaneously */
content: open-quote chapter_counter;

/* Global values */
content: inherit;
content: initial;
content: unset;

Resource

177 questions
20
votes
2 answers

Css Content, Attr and Url in the same sentence

I have used the content attribute for a long time, and today I wanted to try something new. Instead of using JS to display a image tooltip I wanted to know if it was possible to do it dynamically with CSS. So I tried: .TableLine:hover:after{ …
h1fra
  • 324
  • 1
  • 3
  • 10
20
votes
3 answers

Using attr(data-icon) property to display unicode before element

Lets demonstrate an example with simple HTML code like this:
Title
I would like this element to have an prefix icon set by it's data attribute (data-icon) so I set CSS file like this: div:before { content:…
20
votes
1 answer

Multiple content: attr() values

I'm trying to display 2 things in my elements; the class name and an own created data-size variable. Seperated with one white space. I could get this working by doing this: .element:before { content: attr(class); } .element:after { content:…
Bas
  • 2,106
  • 5
  • 21
  • 59
19
votes
1 answer

How did CSS `content` property work for `img` element in WebKit?

Long time ago there was a draft of CSS3 Generated Content spec which allowed the content property for any HTML element (not only ::before/::after pseudo-elements), without any formal restriction for empty or replaced elements. It was once supported…
Ilya Streltsyn
  • 13,076
  • 2
  • 37
  • 57
19
votes
2 answers

after pseudo element not appearing in code

I'm trying to use the after pseudo element to add some effects to a site.
19
votes
1 answer

add css content text in 'empty' divs

See this fiddle: http://jsfiddle.net/xanld/3yh28/ div:before { content: 'This div is empty'; } div:empty { background:red; } I'd like to add css content to empty divs only. I can either use the :empty selector, but I need to use the :before…
xanld
  • 977
  • 1
  • 11
  • 22
18
votes
10 answers

Color "transparent" not working

I have a problem with the IE (what else?): I generate content with CSS which has also a background-image. I looks like that: #nav ul li:after { content: "--"; position: relative; z-index: 99; background: transparent url(image.png); …
Poru
  • 8,254
  • 22
  • 65
  • 89
18
votes
1 answer

Nested css counters with leading zeros

Is it possible to combine the css counters() function with leading zeros, producing a list such as this: Item 01 Item 01.01 Item 01.02 Item 01.02.01 Leading zeros are possible using content: counter(name, decimal-leading-zero), and…
Jason
  • 183
  • 1
  • 1
  • 5
15
votes
3 answers

How to avoid line breaks after ":before" in CSS

On my website I'm using font icons for certain link types. These icons are added via :before CSS syntax. a.some-link:before { font-family: icons; display: inline-block; padding-right: 0.3em; content: 'x'; } However, when this link is at the…
Sebastian Krysmanski
  • 8,114
  • 10
  • 49
  • 91
14
votes
3 answers

Can you apply a width to a :before/:after pseudo-element (content:url(image))?

This is in addition to my recent question: Is it possible to use pseudo-elements to make containing elements wrap around an absolutely-positioned element (like a clearfix)? JSFiddle: http://jsfiddle.net/derekmx271/T7A7M/ I'm trying to use…
Derek Foulk
  • 1,892
  • 1
  • 19
  • 37
13
votes
2 answers

'content' attribute to inherit node value

Is there a way to inherit node value into content attribute? Like, if

tag value is set to "Random title", can I get this value inside content attribute in CSS? I've tried content: inherit;, but it doesn't seem to work. An example of my…

tomsseisums
  • 13,168
  • 19
  • 83
  • 145
13
votes
2 answers

Add HTML tag inside CSS Content property

I'm looking for a way to add an HTML tag for CSS content property inside :after and :before. Unlike this question which only discusses adding symbols like <. What I'm trying to add is something like: .breadcrumbs li a:before { content: '
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
12
votes
1 answer

Is it possible to make CSS generated content searchable by a browser?

I run a website that uses CSS pseudo-elements to insert text here and there. One of them inserts the value of a CSS counter (whereupon it would require considerable re-engineering of the system to do this without CSS text injection). The specific…
Andrew Stacey
  • 1,004
  • 8
  • 17
11
votes
5 answers

How can I get IE8 to accept a CSS :before tag?

I have the following CSS code .editable:before { content: url(../images/icons/icon1.png); padding-right:5px; } this is used in conjunction with the following markup: In every other blessed browser in the…
William Calleja
  • 4,055
  • 11
  • 41
  • 51
11
votes
1 answer

Testing CSS counters using Cucumber / Selenium

One of the requirements I'm trying to create step definitions for is that each element should be numbered. Is there an API for checking whether an item has the correct CSS generated content? We're using Selenium, Cucumber & Capybara to test our…
Simon Scarfe
  • 9,378
  • 4
  • 28
  • 32
1
2
3
11 12