Propiedad de contenido CSS
Ejemplo
El siguiente ejemplo inserta el valor del atributo href entre paréntesis después de cada elemento <a>:
a::after {
content: " (" attr(href) ")";
}
Más ejemplos de "Pruébelo usted mismo" a continuación.
Definición y uso
La content
propiedad se utiliza con los
pseudoelementos ::before y ::after , para insertar contenido generado.
Valor por defecto: | normal |
---|---|
Heredado: | No |
Animable: | No. Leer sobre animable |
Versión: | CSS2 |
Sintaxis de JavaScript: | No puede dar a un elemento una pseudoclase usando JavaScript, pero hay otras formas de obtener el mismo resultado: |
Compatibilidad con navegador
Los números de la tabla especifican la primera versión del navegador que es totalmente compatible con la propiedad.
Property | |||||
---|---|---|---|---|---|
content | 1.0 | 8.0 | 1.0 | 1.0 | 4.0 |
Sintaxis CSS
content: normal|none|counter|attr|string|open-quote|close-quote|no-open-quote|no-close-quote|url|initial|inherit;
Valores de propiedad
Value | Description | Example |
---|---|---|
normal | Default value. Sets the content, if specified, to normal, which default is "none" (which is nothing) | |
none | Sets the content, if specified, to nothing | |
counter | Sets the content as a counter | |
attr(attribute) | Sets the content as one of the selector's attribute | |
string | Sets the content to the text you specify | |
open-quote | Sets the content to be an opening quote | |
close-quote | Sets the content to be a closing quote | |
no-open-quote | Removes the opening quote from the content, if specified | |
no-close-quote | Removes the closing quote from the content, if specified | |
url(url) | Sets the content to be some kind of media (an image, a sound, a video, etc.) | |
initial | Sets this property to its default value. Read about initial | |
inherit | Inherits this property from its parent element. Read about inherit |
Más ejemplos
Ejemplo
Cómo agregar colores de viñetas para <ul> o <ol> eliminando sus viñetas predeterminadas y agregando una entidad HTML que parece viñetas (•):
ul {
list-style: none; /* Remove HTML bullets */
padding: 0;
margin: 0;
}
li {
padding-left: 16px;
}
li::before {
content: "•"; /* Insert content that looks like bullets */
padding-right: 8px;
color: blue; /* Or a color you prefer */
}
páginas relacionadas
Referencia CSS: :: antes del pseudo elemento
Referencia CSS: ::después del pseudo elemento