diff options
Diffstat (limited to 'files/es/web/css/attr/index.html')
-rw-r--r-- | files/es/web/css/attr/index.html | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/files/es/web/css/attr/index.html b/files/es/web/css/attr/index.html new file mode 100644 index 0000000000..5efb73b796 --- /dev/null +++ b/files/es/web/css/attr/index.html @@ -0,0 +1,183 @@ +--- +title: attr +slug: Web/CSS/attr +translation_of: Web/CSS/attr() +original_slug: Web/CSS/attr() +--- +<p>{{ CSSRef() }}</p> + +<h2 id="Resumen">Resumen</h2> + +<p>La función <code>attr()</code> de <a href="/en-US/docs/Web/CSS">CSS</a> se usa para recuperar el valor de un atributo del elemento seleccionado y usarlo en la hoja de estilos. Se puede usar también en un pseudo-elemento y, en este caso, el valor del atributo en el elemento originado del pseudo-elemento es devuelto.</p> + +<p>La función <code>attr()</code> de <a href="/en-US/docs/Web/CSS">CSS</a> se puede usar con cualquier propiedad de CSS. {{ experimental_inline() }}</p> + +<h2 id="Sintaxis">Sintaxis</h2> + +<pre class="syntaxbox notranslate"><a href="/en-US/docs/Web/CSS/Value_definition_syntax">Sintaxis formal</a>: attr( attribute-name <type-or-unit>? [, <fallback> ]? ) +</pre> + +<h3 id="Valores">Valores</h3> + +<dl> + <dt><code>attribute-name</code></dt> + <dd>Es el nombre de un atributo en el elemento HTML al que se hace referencia en el CSS. Soporte para otros atributos a parte de {{ cssxref("content") }} es {{ experimental_inline() }}.</dd> + <dt><code><type-</code>or-unit></dt> + <dd>Es una palabra clave que representa o el tipo del valor del atributo, o su unidad, pues en HTML algunos atributos tienen unidades implícitas. Si el uso de <code><type-or-unit></code> como valor del atributo especificado no es válido, la expresión <code>attr()</code> también será no válida. Si se omite, el valor por defecto es string. La lista de valores válidos son: + <table class="standard-table"> + <thead> + <tr> + <th scope="col">Keyword</th> + <th scope="col">Associated type</th> + <th scope="col">Comment</th> + <th scope="col">Default value</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>string</code></td> + <td>{{cssxref("<string>")}}</td> + <td>El valor del atributo es tratado como una {{cssxref("<string>")}} de CSS. No se reparsea, y en este caso particular los caracteres son usados tal y como son en vez de convertirlos en diferentes caracteres de CSS.</td> + <td>Cadena vacía</td> + </tr> + <tr> + <td><code>color</code> {{ experimental_inline() }}</td> + <td>{{cssxref("<color>")}}</td> + <td>El valor del atributo es tratado como hash (3- or 6-value hash) o a una palabra clave. Debe ser un valor válido de una {{cssxref("<string>")}} de CSS.<br> + Los espacios iniciales y finales son eliminados.</td> + <td><code>currentColor</code></td> + </tr> + <tr> + <td><code>url</code> {{ experimental_inline() }}</td> + <td>{{ cssxref("<uri>") }}</td> + <td>El valor del atributo es tratado como una cadena que se usa en una función <code>url()</code> de CSS.<br> + URLs relativas se resuelven con respecto al documento original, no respecto a la hoja de estilos. Los espacios iniciales y finales son eliminados.</td> + <td>La url <code>about:invalid</code> que apunta a un documento inexistente con una condición de error genérico.</td> + </tr> + <tr> + <td><code>integer</code> {{ experimental_inline() }}</td> + <td>{{cssxref("<integer>")}}</td> + <td>El valor del atributo es tratado como un {{cssxref("<integer>")}} CSS. Si no es válido, si no es un entero o está fuera del rango aceptado por la propiedad CSS, se usa el valor por defecto.<br> + Los espacios iniciales y finales son eliminados.</td> + <td><code>0</code>, or, if <code>0</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + <tr> + <td><code>number</code> {{ experimental_inline() }}</td> + <td>{{cssxref("<number>")}}</td> + <td>El valor del atributo es tratado como {{cssxref("<number>")}}. Si no es válido, si no es un número o está fuera del rango aceptado por la propiedad CSS, se usa el valor por defecto.<br> + Los espacios iniciales y finales son eliminados.</td> + <td><code>0</code>, or, if <code>0</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + <tr> + <td><code>length</code> {{ experimental_inline() }}</td> + <td>{{cssxref("<length>")}}</td> + <td>The attribute value is parsed as a CSS {{cssxref("<length>")}} dimension, that is including the unit (e.g. <code>12.5em</code>). If it is not valid, that is not a length or out of the range accepted by the CSS property, the default value is used.<br> + If the given unit is a relative length, <code>attr()</code>computes it to an absolute length.<br> + Leading and trailing spaces are stripped.</td> + <td><code>0</code>, or, if <code>0</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + <tr> + <td><code>em</code>, <code>ex</code>, <code>px</code>, <code>rem</code>, <code>vw</code>, <code>vh</code>, <code>vmin</code>, <code>vmax</code>, <code>mm</code>, <code>cm</code>, <code>in</code>, <code>pt</code>, or <code>pc</code> {{ experimental_inline() }}</td> + <td>{{cssxref("<length>")}}</td> + <td>The attribute value is parsed as a CSS {{cssxref("<number>")}}, that is without the unit (e.g. <code>12.5</code>), and interpreted as a {{cssxref("<length>")}} with the specified unit. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used.<br> + If the given unit is a relative length, <code>attr()</code>computes it to an absolute length.<br> + Leading and trailing spaces are stripped.</td> + <td><code>0</code>, or, if <code>0</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + <tr> + <td><code>angle</code> {{ experimental_inline() }}</td> + <td>{{ cssxref("<angle>") }}</td> + <td>The attribute value is parsed as a CSS {{ cssxref("<angle>") }} dimension, that is including the unit (e.g. <code>30.5deg</code>). If it is not valid, that is not an angle or out of the range accepted by the CSS property, the default value is used.<br> + Leading and trailing spaces are stripped.</td> + <td><code>0deg</code>, or, if <code>0deg</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + <tr> + <td><code>deg</code>, <code>grad</code>, <code>rad</code> {{ experimental_inline() }}</td> + <td>{{ cssxref("<angle>") }}</td> + <td>The attribute value is parsed as a CSS {{cssxref("<number>")}}, that is without the unit (e.g. <code>12.5</code>), and interpreted as an {{ cssxref("<angle>") }} with the specified unit. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used.<br> + Leading and trailing spaces are stripped.</td> + <td><code>0deg</code>, or, if <code>0deg</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + <tr> + <td><code>time</code> {{ experimental_inline() }}</td> + <td>{{cssxref("<time>")}}</td> + <td>The attribute value is parsed as a CSS {{cssxref("<time>")}} dimension, that is including the unit (e.g. <code>30.5ms</code>). If it is not valid, that is not a time or out of the range accepted by the CSS property, the default value is used.<br> + Leading and trailing spaces are stripped.</td> + <td><code>0s</code>, or, if <code>0s</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + <tr> + <td><code>s</code>, <code>ms</code> {{ experimental_inline() }}</td> + <td>{{cssxref("<time>")}}</td> + <td>The attribute value is parsed as a CSS {{cssxref("<number>")}}, that is without the unit (e.g. <code>12.5</code>), and interpreted as an{{cssxref("<time>")}} with the specified unit. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used.<br> + Leading and trailing spaces are stripped.</td> + <td><code>0s</code>, or, if <code>0s</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + <tr> + <td><code>frequency</code> {{ experimental_inline() }}</td> + <td>{{cssxref("<frequency>")}}</td> + <td>The attribute value is parsed as a CSS {{cssxref("<frequency>")}} dimension, that is including the unit (e.g. <code>30.5kHz</code>). If it is not valid, that is not a frequency or out of the range accepted by the CSS property, the default value is used.</td> + <td><code>0Hz</code>, or, if <code>0Hz</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + <tr> + <td><code>Hz</code>, <code>kHz</code> {{ experimental_inline() }}</td> + <td>{{cssxref("<frequency>")}}</td> + <td>The attribute value is parsed as a CSS {{cssxref("<number>")}}, that is without the unit (e.g. <code>12.5</code>), and interpreted as a {{cssxref("<frequency>")}} with the specified unit. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used.<br> + Leading and trailing spaces are stripped.</td> + <td><code>0Hz</code>, or, if <code>0Hz</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + <tr> + <td><code>%</code> {{ experimental_inline() }}</td> + <td>{{cssxref("<percentage>")}}</td> + <td>The attribute value is parsed as a CSS {{cssxref("<number>")}}, that is without the unit (e.g. <code>12.5</code>), and interpreted as a {{cssxref("<percentage>")}}. If it is not valid, that is not a number or out of the range accepted by the CSS property, the default value is used.<br> + If the given value is used as a length, <code>attr()</code>computes it to an absolute length.<br> + Leading and trailing spaces are stripped.</td> + <td><code>0%</code>, or, if <code>0%</code> is not a valid value for the property, the property's minimum value.</td> + </tr> + </tbody> + </table> + </dd> + <dt><code><fallback></code></dt> + <dd>The value to be used if the associated attribute is missing or contains an invalid value. The fallback value must be valid where <code>attr()</code> is used, even if it is not used, and must not contain another <code>attr()</code> expression. If <code>attr()</code> is not the sole component value of a property, its <code><fallback></code> value must be of the type defined by <code><type-or-unit></code>. If not set, CSS will use the default value defined for each <code><type-or-unit></code>.</dd> +</dl> + +<h2 id="Examples">Examples</h2> + +<pre class="brush: css notranslate">p::before { + content:attr(data-foo) " "; +} +</pre> + +<pre class="brush: html notranslate"><p data-foo="hello">world</p> +</pre> + +<h3 id="Result">Result</h3> + +<p>{{ EmbedLiveSample("Examples", '100%', '80') }}</p> + +<h2 id="Specifications" name="Specifications">Specifications</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{ SpecName('CSS3 Values', '#attr', 'attr()') }}</td> + <td>{{ Spec2('CSS3 Values') }}</td> + <td>Added two optional parameters; can be used on all properties; may return other values than {{cssxref("<string>")}}. These changes are {{ experimental_inline() }} and may be dropped during the CR phase if browser support is too small.</td> + </tr> + <tr style="vertical-align: top;"> + <td style="vertical-align: top;">{{ SpecName('CSS2.1', 'generate.html#x18', 'attr()') }}</td> + <td style="vertical-align: top;">{{ Spec2('CSS2.1') }}</td> + <td style="vertical-align: top;">Limited to the {{ cssxref("content") }} property; always return a {{cssxref("<string>")}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +{{Compat("css.types.attr")}} |