Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

content

Este artigo necessita de uma revisão técnica. Como posso ajudar.

Este artigo necessita de uma revisão editorial. Como posso ajudar.

Resumo

O conteúdo CSS da propriedade CSS é usado com o  ::before::after pseudo-elementos para gerar conteúdo em um elemento.  Objetos inseridos usando o conteúdo de propriedade são anônimos  elementos substituídos.

Initial valuenormal
Aplica-se a::before and ::after pseudo-elements
Inheritednão
Midiaall
Computed valueOn elements, always computes to normal. On ::before and ::after, if normal is specified, computes to none. Otherwise, for URI values, the absolute URI; for attr() values, the resulting string; for other keywords, as specified.
Animatablenão
Canonical orderthe unique non-ambiguous order defined by the formal grammar

Sintaxe

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

/* <string> value, non-latin characters must be encoded */
/* e.g. \00A0 for &nbsp; */
content: 'prefix';

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

/* <counter> values */
content: chapter_counter;

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

/* Language- and position-dependant 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;

Valores

none
The pseudo-element is not generated.
normal
Computes to none for the :before and :after pseudo-elements.
<string>
Text content.
<uri> or url()
The value is a URI that designates an external resource (such as an image). If the resource or image can't be displayed, it is either ignored or some placeholder shows up.
<counter>
Counters may be specified with two different functions: 'counter()' or 'counters()'. The former has two forms: 'counter(name)' or 'counter(name, style)'. The generated text is the value of the innermost counter of the given name in scope at this pseudo-element; it is formatted in the indicated style ('decimal' by default). The latter function also has two forms: 'counters(name, string)' or 'counters(name, string, style)'. The generated text is the value of all counters with the given name in scope at this pseudo-element, from outermost to innermost separated by the specified string. The counters are rendered in the indicated style ('decimal' by default). See the section on automatic counters and numbering for more information. The name must not be 'none', 'inherit' or 'initial'. Such a name causes the declaration to be ignored.
attr(X)
Returns the value of the element's attribute X as a string. If there is no attribute X, an empty string is returned. The case-sensitivity of attribute names depends on the document language.
open-quote | close-quote
These values are replaced by the appropriate string from the quotes property.
no-open-quote | no-close-quote
Introduces no content, but increments (decrements) the level of nesting for quotes.

Formal syntax

normal | none | [ <string> | <uri> | <counter> | attr() | open-quote | close-quote | no-open-quote | no-close-quote ]+

Exemplos

Código simples - headings and quotes

Conteúdo em HTML 

<h1>5</h1>
<p> We shall start this with a quote from Sir Tim Berners-Lee,
    <q cite="https://www.w3.org/People/Berners-Lee/FAQ.html#Internet">
        I was lucky enough to invent the Web at the time when the Internet already existed - and had for a decade and a half.</q>  We must understand that there is nothing fundamentally wrong with building on the contributions of others.
</p>

<h1>6</h1>
<p> Here we shall quote the Mozilla Manifesto,
    <q cite="https://www.mozilla.org/en-US/about/manifesto/">
        Individuals must have the ability to shape the Internet and their own experiences on the Internet.</q> And so, we can infer that contributing to the open web, can protect our own individual experiences on it.
</p>

Conteúdo em CSS 

q {
    color: #00008B;
    font-style: italic;
}

q::before   { content: open-quote }
q::after    { content: close-quote }

h1::before  { content: "Chapter "; }

Output

Conteúdo em HTML 

<a href="https://www.mozilla.org/en-US/">Home Page</a>

Conteúdo em CSS 

a::before{
    content: url(https://www.mozilla.org/favicon.ico) " MOZILLA: ";
    font:    x-small Arial,freeSans,sans-serif;
    color:   gray;
}

Output

Code sample - class based example

Conteúdo em HTML 

<h2>Paperback best sellers</h2>
<ol>
    <li>Political thriller</li>
    <li class="newEntry">Halloween Stories</li>
    <li>My Biography</li>    
    <li class="newEntry">Vampire Romance</li>
</ol>

Conteúdo em CSS 

/* use a class rather that an element selector to give more flexibility.
Below is a simple string example, but don't forget add a leading space
in the text string for spacing purposes */

.newEntry::after {
    content: " New!";
    color: red;
}

Output

Conteúdo em HTML 

<ul>
    <li><a id="moz" href="https://www.mozilla.org/">
        Mozilla Home Page</a></li>
    <li><a id="mdn" href="https://developer.mozilla.org/">
        Mozilla Developer Network</a></li>
</ul>

Conteúdo em CSS 

a {
    text-decoration: none;
    border-bottom: 3px dotted navy;
}

a::after {
    content: " (" attr(id) ")";
}

#moz::before {
    content:url(https://mozorg.cdn.mozilla.net/media/img/favicon.ico) ;
}

#mdn::before {
    content:url(https://mdn.mozillademos.org/files/7691/mdn-favicon16.png) ;
}

li {
    margin: 1em;
}

Output

Especificações

Specification Status Comment
CSS Level 2 (Revision 1)
The definition of 'content' in that specification.
Recommendation Initial definition

Compatibilidade com navegador

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 1.0 (1.7 or earlier) 8.0 4.0 1.0
url() support 1.0 1.0 (1.7 or earlier) 8.0 7.0 1.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 1.0 (1.0) 8.0 9.5 1.0

Veja também

Resumo

O conteúdo CSS da propriedade CSS é usado com o  ::before::after pseudo-elementos para gerar conteúdo em um elemento.  Objetos inseridos usando o conteúdo de propriedade são anônimos  elementos substituídos.

Initial valuenormal
Aplica-se a::before and ::after pseudo-elements
Inheritednão
Midiaall
Computed valueOn elements, always computes to normal. On ::before and ::after, if normal is specified, computes to none. Otherwise, for URI values, the absolute URI; for attr() values, the resulting string; for other keywords, as specified.
Animatablenão
Canonical orderthe unique non-ambiguous order defined by the formal grammar

Sintaxe

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

/* <string> value, non-latin characters must be encoded */
/* e.g. \00A0 for &nbsp; */
content: 'prefix';

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

/* <counter> values */
content: chapter_counter;

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

/* Language- and position-dependant 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;

Valores

none
The pseudo-element is not generated.
normal
Computes to none for the :before and :after pseudo-elements.
<string>
Text content.
<uri> or url()
The value is a URI that designates an external resource (such as an image). If the resource or image can't be displayed, it is either ignored or some placeholder shows up.
<counter>
Counters may be specified with two different functions: 'counter()' or 'counters()'. The former has two forms: 'counter(name)' or 'counter(name, style)'. The generated text is the value of the innermost counter of the given name in scope at this pseudo-element; it is formatted in the indicated style ('decimal' by default). The latter function also has two forms: 'counters(name, string)' or 'counters(name, string, style)'. The generated text is the value of all counters with the given name in scope at this pseudo-element, from outermost to innermost separated by the specified string. The counters are rendered in the indicated style ('decimal' by default). See the section on automatic counters and numbering for more information. The name must not be 'none', 'inherit' or 'initial'. Such a name causes the declaration to be ignored.
attr(X)
Returns the value of the element's attribute X as a string. If there is no attribute X, an empty string is returned. The case-sensitivity of attribute names depends on the document language.
open-quote | close-quote
These values are replaced by the appropriate string from the quotes property.
no-open-quote | no-close-quote
Introduces no content, but increments (decrements) the level of nesting for quotes.

Formal syntax

normal | none | [ <string> | <uri> | <counter> | attr() | open-quote | close-quote | no-open-quote | no-close-quote ]+

Exemplos

Código simples - headings and quotes

Conteúdo em HTML 

<h1>5</h1>
<p> We shall start this with a quote from Sir Tim Berners-Lee,
    <q cite="https://www.w3.org/People/Berners-Lee/FAQ.html#Internet">
        I was lucky enough to invent the Web at the time when the Internet already existed - and had for a decade and a half.</q>  We must understand that there is nothing fundamentally wrong with building on the contributions of others.
</p>

<h1>6</h1>
<p> Here we shall quote the Mozilla Manifesto,
    <q cite="https://www.mozilla.org/en-US/about/manifesto/">
        Individuals must have the ability to shape the Internet and their own experiences on the Internet.</q> And so, we can infer that contributing to the open web, can protect our own individual experiences on it.
</p>

Conteúdo em CSS 

q {
    color: #00008B;
    font-style: italic;
}

q::before   { content: open-quote }
q::after    { content: close-quote }

h1::before  { content: "Chapter "; }

Output

Conteúdo em HTML 

<a href="https://www.mozilla.org/en-US/">Home Page</a>

Conteúdo em CSS 

a::before{
    content: url(https://www.mozilla.org/favicon.ico) " MOZILLA: ";
    font:    x-small Arial,freeSans,sans-serif;
    color:   gray;
}

Output

Code sample - class based example

Conteúdo em HTML 

<h2>Paperback best sellers</h2>
<ol>
    <li>Political thriller</li>
    <li class="newEntry">Halloween Stories</li>
    <li>My Biography</li>    
    <li class="newEntry">Vampire Romance</li>
</ol>

Conteúdo em CSS 

/* use a class rather that an element selector to give more flexibility.
Below is a simple string example, but don't forget add a leading space
in the text string for spacing purposes */

.newEntry::after {
    content: " New!";
    color: red;
}

Output

Conteúdo em HTML 

<ul>
    <li><a id="moz" href="https://www.mozilla.org/">
        Mozilla Home Page</a></li>
    <li><a id="mdn" href="https://developer.mozilla.org/">
        Mozilla Developer Network</a></li>
</ul>

Conteúdo em CSS 

a {
    text-decoration: none;
    border-bottom: 3px dotted navy;
}

a::after {
    content: " (" attr(id) ")";
}

#moz::before {
    content:url(https://mozorg.cdn.mozilla.net/media/img/favicon.ico) ;
}

#mdn::before {
    content:url(https://mdn.mozillademos.org/files/7691/mdn-favicon16.png) ;
}

li {
    margin: 1em;
}

Output

Especificações

Specification Status Comment
CSS Level 2 (Revision 1)
The definition of 'content' in that specification.
Recommendation Initial definition

Compatibilidade com navegador

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 1.0 (1.7 or earlier) 8.0 4.0 1.0
url() support 1.0 1.0 (1.7 or earlier) 8.0 7.0 1.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 1.0 (1.0) 8.0 9.5 1.0

Veja também

Etiquetas do documento e colaboradores

 Colaboradores desta página: SphinxKnight
 Última atualização por: SphinxKnight,