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
0
votes
3 answers

How to cancel the inheritance of the "li:before {content: 'text'}" without reassigning it for each
  • element?
  • everyone! The general goal is that all li elements for which a property is not explicitly declared use the standard value. I don't understand why the content property can't be reset: ul { position: relative; list-style: none; margin-left: 0; …
    isNaN
    • 11
    • 5
    0
    votes
    1 answer

    Pseudoelement's content doesn't get updated in IE11

    I have the following code: someSelector:after { content: attr('data-some-data'); /* ... */ } Everything works fine (the value is reflected on the screen) until I change this attribute to something…
    gribvirus74
    • 755
    • 6
    • 20
    0
    votes
    1 answer

    CSS content attribute: loading text from a TXT file

    I need to know if it's possible to load text from a TXT file with the CSS "content" attribute? I searched around and didn't find anything. I have the following CSS: .custom div.ot-loginPageCopyright::after { content: url('copyright.txt'); …
    0
    votes
    1 answer

    Add svg to content property

    I want to add the svg link inside the content property. Can I do it? .selectedItem::before{ content: " any svg link ";
    by-brt
    • 45
    • 7
    0
    votes
    1 answer

    Using css pseudo element in php doesn´t work

    My issue is that I had to add in php the tag in order to put there some styles with pseudo element span: before and a content: 'text' in which I have a translation for serveral languages. Of course, has already been added and the rest of special…
    0
    votes
    2 answers

    Any way to fix CSS3 content attribute flicker in Chrome?

    I've created a page where I use this type of styling: nav ul li:before { content: " / "; } nav ul li:last-child:before { content: ""; } Where most of the time, I want a "/" before the li elements except on the last one. The problem is that in…
    jaketrent
    • 1,173
    • 11
    • 25
    0
    votes
    2 answers

    Do CSS rules exist for placing content within elements and positioning them?

    Do CSS rules exist for placing content such as images or text within elements? eg. say I have a div which can contain some info which is correct and some info which is wrong, can I have rules such as: .correct { img: greenTick.jpg; text: "answer…
    vfclists
    • 19,193
    • 21
    • 73
    • 92
    0
    votes
    3 answers

    Centering container in CSS, after deleting a 4th box

    I have deleted a 4th box as i only need 3 and want the centre the 3 boxes. Here is an image. This is my CSS Code. Below is the HTML code, Keeps saying there is too much code so I am filling up this part with more text so hopefully I can get some…
    0
    votes
    1 answer

    Making content appear below the :before pseudo selector?

    I have an element
    The result is ...
    The Test_then class looks like this: .Test_then::before { content: 'Then'; } My goal is to have the (The result is ...) appear below the Then content added by the Test_then class. …
    Ole
    • 41,793
    • 59
    • 191
    • 359
    0
    votes
    2 answers

    Semantic way of stacking two characters in a ::before element?

    I'm trying to add checklist symbols to the left edge of table cells. So far, this does work. When I'm trying to stack another char on top of the checklist symbol though, things get ugly. I have found several ways to achieve the result I'm after,…
    Tatjana Heuser
    • 964
    • 9
    • 11
    0
    votes
    1 answer

    CSS selector and content property to add a space character between two inline-block elements

    I have a series of span elements of class tag (from bootstrap v4) which are adjacent to each other without any space between them because they come from a reacj.js array of JSX elements : text
    beeb
    • 1,187
    • 11
    • 32
    0
    votes
    1 answer

    Adjacent content: url() table elements result in incorrect table layout

    I have a 3-column x 2-row table layout. Each row has two elements populated by content:url() In the first row, they are separated by an empty element and layout correctly In the second row, they are adjacent. Both Chrome and Safari place the second…
    Jason
    • 9,408
    • 5
    • 36
    • 36
    0
    votes
    1 answer

    Avoid applying style to :after when using :hover

    I am using :after to allow myself a border with a radius and a gradient, like: #main .element { border-radius: 10px; background: #FFF; } #main .element:after { border-radius: 10px; background: linear-gradient(red,…
    William Paul
    • 337
    • 1
    • 4
    • 13
    0
    votes
    1 answer

    Can I use CSS content and counters to add custom labels to my grid?

    I'm currently creating a html grid out of divs to display a characters attributes. Here is the DIV:
    AncientSwordRage
    • 7,086
    • 19
    • 90
    • 173