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
11
votes
6 answers

Input placeholder using CSS only

I know there are lot's of questions regarding this query here but none of them provide the solution for me. HTML

This is not done.

CSS p.note1:before{ content:…
Akki619
  • 2,386
  • 6
  • 26
  • 56
10
votes
4 answers

Div with CSS content, after pseudo element is not visible

I have a POC that I have to complete and I am only allowed to use CSS to update the styles of a product. I have replaced one of the images of the product with a logo by using the CSS content attribute. I have to add a simple string with a phone…
ICodeGorilla
  • 588
  • 1
  • 5
  • 26
10
votes
2 answers

Is it possible to use (multiple) font styles within CSS `content`?

I've got a CSS element set up to insert some content, via: .foo:after { content: "Bold, italics"; } I'd like the word "Bold" to be rendered in a bold font-weight and the word "italics" to be rendered in an italics font-style. I know it's possible…
Alec Jacobson
  • 6,032
  • 5
  • 51
  • 88
10
votes
3 answers

Why does IE10 require the presence of a p:hover {} rule for transitions to work on a pseudo element?

HTML:

Hover

CSS: p::after { content: " here"; transition: all 1s; } p:hover::after { font-size: 200%; color: red; } Live demo: http://jsfiddle.net/SPHzj/13/ (works in Firefox and Chrome) As you can see, I've set up CSS…
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385
9
votes
2 answers

css form checkbox styling with checked and after tags

I am trying to design a form without using JavaScript or JQuery. It includes a series of checkboxes. The idea is to display a certain gif after the checkbox if it is unchecked. Otherwise, display nothing after it. This is the code I…
user1316401
  • 455
  • 1
  • 4
  • 13
8
votes
1 answer

Is it possible to use CSS Custom Properties in values for the content property?

Example: :root { --PrimaryThemeColor: #3acfb6; /* with or without quotes */ } .ColorSwatch:after { content: var(--PrimaryThemeColor); } When this is rendered, the computed CSS is literally that value. content:…
Kevin Suttle
  • 8,358
  • 3
  • 33
  • 37
8
votes
3 answers

CSS ::before pseudo-element line-height?

My paragraph has a height/line-height of 50px and text-align: center, which centers the text. But p:before is causing it to increase in height/line-height, causing the text to bump down. I want both p and p:before to be vertically centered.…
Sunny
  • 2,232
  • 7
  • 24
  • 36
8
votes
2 answers

Is declaring "content" property on :before and :after for every element a massive performance issue?

As you probably know, if you will to use :before and/or :after pseudoelements without setting text in it, you still have to declare content: ''; on them to make them visible. I just added the following to my base stylesheet : *:before, *:after { …
neemzy
  • 1,899
  • 23
  • 25
8
votes
2 answers

Cannot change the content of visited :before pseudo-elements

I was trying to add some effects for visited links, then I got this problem. Here is the code: http://dabblet.com/gist/5447894 Only Opera can successfully change the content of :before pseudo-elements. All other browsers are fail. Did I miss…
Peiwen
  • 682
  • 7
  • 15
8
votes
2 answers

How to keep a pseudo-element fixed within a scrolled element?

How can I get this effect:

body{
  position: relative; 
  @include background(linear-gradient(left, lighten($me, 11%), lighten($me, 11%) 
    $half,…
aurel
  • 3,082
  • 10
  • 44
  • 56
7
votes
3 answers

Various possible uses of the "content: " property in css2/css3

I'm trying to find some uptodate info about various possible uses for content: property in css but only find stuff in the ancients dungeons of the web dating from 2004 orso so I thought I have to ask this in 2011 again: p:before { content:…
Sam
  • 15,254
  • 25
  • 90
  • 145
7
votes
2 answers

Why I can not use space after on :before :after content when using unicode

I just was wondering why in CSS when using unicode I can not put space after unicode : This is my test : div {font-size:50px;} div:before, div:after {color:green;} .a:before {content: 'text-before \2022 ';} .b:before {content: 'text-before •…
l2aelba
  • 21,591
  • 22
  • 102
  • 138
7
votes
1 answer

CSS pseudo after/before using content or background for img?

As for pseudo-elements :after/:before there are apparently two ways if I want to display image there: using background-image:url(imgurl.png); using content:url(imgurl.png); Are both ways correct and valid? Why should I be using one way over…
Jakub Kolčář
  • 307
  • 1
  • 5
  • 12
7
votes
3 answers

Purpose of *:before, *:after rule without content property

From what I understand, :before and :after inserts content before or after the indicated target. I'm not really sure what would be the purpose of this CSS snippet? *, *:before, *:after { -moz-box-sizing: border-box; }
FiveTools
  • 5,970
  • 15
  • 62
  • 84
7
votes
1 answer

Image overlay using :after pseudo-element

I'm trying to overlay a transparent image over another via the after property. It's not even showing up using this method. I wanna use a base64 encoded image if at all possible. I tried with a regular non-encoded image too. No dice. Anyone have any…
Dave Rottino
  • 1,037
  • 3
  • 22
  • 49
1 2
3
11 12