aboutsummaryrefslogtreecommitdiff
path: root/files/ru/web/css/attr()/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ru/web/css/attr()/index.html')
-rw-r--r--files/ru/web/css/attr()/index.html202
1 files changed, 202 insertions, 0 deletions
diff --git a/files/ru/web/css/attr()/index.html b/files/ru/web/css/attr()/index.html
new file mode 100644
index 0000000000..dfcd64f78f
--- /dev/null
+++ b/files/ru/web/css/attr()/index.html
@@ -0,0 +1,202 @@
+---
+title: attr
+slug: Web/CSS/attr()
+translation_of: Web/CSS/attr()
+---
+<div>{{CSSRef}}</div>
+
+<h2 id="Описание">Описание</h2>
+
+<p>С помощью функции <a href="/en-US/docs/Web/CSS">CSS</a> <code>attr()</code> можно извлекать значение атрибута выбранного элемента и использовать это значение в таблице стилей. Функция работает и с псевдо-элементами. В этом случае возвращается значение атрибута элемента, для которого формируется <a href="/en-US/docs/Web/CSS/Pseudo-elements">псевдо-элемент</a>.</p>
+
+<p>Функцию <code>attr()</code> можно использовать с любым свойством CSS, но поддержка иных свойств, кроме {{cssxref("content")}}, является экспериментальной.</p>
+
+<h2 id="Синтаксис">Синтаксис</h2>
+
+<pre class="brush:js notranslate">/* Пример простого использования */
+attr(data-count);
+attr(title);
+
+/* С типом */
+attr(src url);
+attr(data-count number);
+attr(data-width px);
+
+/* с фоллбэком */
+attr(data-count number, 0);
+attr(src url, '');
+attr(data-width px, inherit);
+attr(data-something, 'default');
+</pre>
+
+<h3 id="Значения">Значения</h3>
+
+<dl>
+ <dt><code>attribute-name</code></dt>
+ <dd>Название атрибута элемента HTML, на который ссылаемся в CSS.</dd>
+ <dt><code style="white-space: nowrap;">&lt;type-or-unit&gt;</code> {{Experimental_Inline}}</dt>
+ <dd>
+ <div class="translate-form__result-text typo typo_text_l i-bem typo_js_inited">Является ключевым словом, представляющим либо тип значения атрибута, либо его единицу, так как в HTML некоторые атрибуты имеют неявные единицы. Если использование <code>&lt;type-or-unit&gt;</code> в качестве значения для данного атрибута недопустимо, выражение <code>attr()</code> также будет недопустимым. Если этот параметр опущен, по умолчанию используется <code>string</code> . Список допустимых значений:</div>
+
+ <table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Ключевое слово</th>
+ <th scope="col">Тип</th>
+ <th scope="col">Комментарий</th>
+ <th scope="col">Значение по умолчанию</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td><code>string</code></td>
+ <td>{{cssxref("&lt;string&gt;")}}</td>
+ <td>The attribute value is treated as a CSS {{cssxref("&lt;string&gt;")}}.  It is NOT reparsed, and in particular the characters are used as-is instead of CSS escapes being turned into different characters.</td>
+ <td>An empty string</td>
+ </tr>
+ <tr>
+ <td><code>color</code> {{experimental_inline}}</td>
+ <td>{{cssxref("&lt;color&gt;")}}</td>
+ <td>The attribute value is parsed as a hash (3- or 6-value hash) or a keyword. It must be a valid CSS {{cssxref("&lt;string&gt;")}} value.<br>
+ Leading and trailing spaces are stripped.</td>
+ <td><code>currentColor</code></td>
+ </tr>
+ <tr>
+ <td><code>url</code> {{experimental_inline}}</td>
+ <td>{{cssxref("&lt;url&gt;")}}</td>
+ <td>The attribute value is parsed as a string that is used inside a CSS <code>url()</code>function.<br>
+ Relative URL are resolved relatively to the original document, not relatively to the style sheet.<br>
+ Leading and trailing spaces are stripped.</td>
+ <td>The url <code>about:invalid</code> that points to a non-existent document with a generic error condition.</td>
+ </tr>
+ <tr>
+ <td><code>integer</code> {{experimental_inline}}</td>
+ <td>{{cssxref("&lt;integer&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;integer&gt;")}}. If it is not valid, that is not an integer 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>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("&lt;number&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;number&gt;")}}. 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>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("&lt;length&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;length&gt;")}} 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("&lt;length&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;number&gt;")}}, that is without the unit (e.g. <code>12.5</code>), and interpreted as a {{cssxref("&lt;length&gt;")}} 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("&lt;angle&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;angle&gt;")}} 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("&lt;angle&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;number&gt;")}}, that is without the unit (e.g. <code>12.5</code>), and interpreted as an {{cssxref("&lt;angle&gt;")}} 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("&lt;time&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;time&gt;")}} 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("&lt;time&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;number&gt;")}}, that is without the unit (e.g. <code>12.5</code>), and interpreted as an{{cssxref("&lt;time&gt;")}} 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("&lt;frequency&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;frequency&gt;")}} 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("&lt;frequency&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;number&gt;")}}, that is without the unit (e.g. <code>12.5</code>), and interpreted as a {{cssxref("&lt;frequency&gt;")}} 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("&lt;percentage&gt;")}}</td>
+ <td>The attribute value is parsed as a CSS {{cssxref("&lt;number&gt;")}}, that is without the unit (e.g. <code>12.5</code>), and interpreted as a {{cssxref("&lt;percentage&gt;")}}. 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>&lt;fallback&gt;</code> {{experimental_inline}}</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>&lt;fallback&gt;</code> value must be of the type defined by <code>&lt;type-or-unit&gt;</code>. If not set, CSS will use the default value defined for each <code>&lt;type-or-unit&gt;</code>.</dd>
+</dl>
+
+<h3 id="Формальный_синтаксис">Формальный синтаксис</h3>
+
+<pre class="syntaxbox notranslate">{{csssyntax}}</pre>
+
+<h2 id="Пример">Пример</h2>
+
+<pre class="brush: css notranslate">p::before {
+ content: attr(data-foo) " ";
+}
+</pre>
+
+<pre class="brush: html notranslate">&lt;p data-foo="hello"&gt;world&lt;/p&gt;
+</pre>
+
+<h3 id="Результат">Результат</h3>
+
+<p>{{EmbedLiveSample("Examples", '100%', '80')}}</p>
+
+<h2 id="Спецификации">Спецификации</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("&lt;string&gt;")}}. These changes are experimental and may be dropped during the CR phase if browser support is too small.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('CSS2.1', 'generate.html#x18', 'attr()')}}</td>
+ <td>{{Spec2('CSS2.1')}}</td>
+ <td>Limited to the {{cssxref("content")}} property; always return a {{cssxref("&lt;string&gt;")}}.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Совместимость_с_браузерами">Совместимость с браузерами</h2>
+
+<p>{{Compat("css.types.attr")}}</p>