diff options
Diffstat (limited to 'files/vi/web/css/content/index.html')
-rw-r--r-- | files/vi/web/css/content/index.html | 296 |
1 files changed, 296 insertions, 0 deletions
diff --git a/files/vi/web/css/content/index.html b/files/vi/web/css/content/index.html new file mode 100644 index 0000000000..188f634136 --- /dev/null +++ b/files/vi/web/css/content/index.html @@ -0,0 +1,296 @@ +--- +title: content +slug: Web/CSS/content +translation_of: Web/CSS/content +--- +<div>{{CSSRef}}</div> + +<p class="summary">The <strong><code>content</code></strong> <a href="/en-US/docs/Web/CSS">CSS</a> property replaces an element with a generated value. Objects inserted using the <code>content</code> property are <strong>anonymous <a href="/en-US/docs/Web/CSS/Replaced_element">replaced elements</a></strong><em>.</em></p> + +<pre class="brush:css no-line-numbers notranslate">/* Keywords that cannot be combined with other values */ +content: normal; +content: none; + +/* <a href="/en-US/docs/Web/CSS/image"><image></a> values */ +content: url("http://www.example.com/test.png"); +content: linear-gradient(#e66465, #9198e5); + +/* alt text for generated content, added in the Level 3 specification */ +content: url("http://www.example.com/test.png") / "This is the alt text"; + +/* values below can only be applied to generated content using ::before and ::after */ + +/* <string> value */ +content: "prefix"; + +/* <a href="/en-US/docs/Web/CSS/counter"><counter></a> values, optionally with <a href="/en-US/docs/Web/CSS/list-style-type"><list-style-type> </a>*/ +content: counter(chapter_counter); +content: counter(chapter_counter, upper-roman); +content: counters(section_counter, "."); +content: counters(section_counter, ".", <code>decimal-leading-zero</code>); + +/* <a href="/en-US/docs/Web/CSS/attr">attr()</a> 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; +</pre> + +<h2 id="Syntax">Syntax</h2> + +<h3 id="Values">Values</h3> + +<dl> + <dt><code>none</code></dt> + <dd>The pseudo-element is not generated.</dd> + <dt><code>normal</code></dt> + <dd>Computes to <code>none</code> for the <code>::before</code> and <code>::after</code> pseudo-elements.</dd> + <dt>{{cssxref("<string>")}}</dt> + <dd>Specifies the "alt text" for the element. This value can be any number of text characters. Non-Latin characters must be encoded using their Unicode escape sequences: for example, <code>\000A9</code> represents the copyright symbol.</dd> + <dt>{{cssxref("<image>")}}</dt> + <dd>An {{cssxref("<image>")}}, denoted by the {{cssxref("<url>")}} or {{cssxref("<gradient>")}} data type, or part of the webpage, defined by the {{cssxref("element", "element()")}} function, denoting the content to display.</dd> + <dt>{{cssxref("<counter>")}}</dt> + <dd>The value of a <a href="/en-US/docs/Web/CSS/CSS_Lists_and_Counters/Using_CSS_counters">CSS counter</a>, generally a number produced by computations defined by {{cssxref("<counter-reset>")}} and {{cssxref("<counter-increment>")}} properies. It can be displayed using either the {{cssxref("counter")}} or {{cssxref("counters")}} function.</dd> + <dd> + <p>The {{cssxref("counter")}} function has two forms: 'counter(<var>name</var>)' or 'counter(<var>name</var>, style)'. The generated text is the value of the innermost counter of the given name in scope at the given pseudo-element. It is formatted in the specified {{cssxref("<list-style-type>")}} (<code>decimal</code> by default).</p> + + <p>The {{cssxref("counters")}} function also has two forms: 'counters(<var>name</var>, <var>string</var>)' or 'counters(<var>name</var>, <var>string</var>, <var>style</var>)'. The generated text is the value of all counters with the given name in scope at the given pseudo-element, from outermost to innermost, separated by the specified string. The counters are rendered in the indicated {{cssxref("<list-style-type>")}} (<code>decimal</code> by default).</p> + </dd> + <dt><code>attr(x)</code></dt> + <dd>The value of the element's attribute <code>x</code> as a string. If there is no attribute <code>x</code>, an empty string is returned. The case-sensitivity of attribute names depends on the document language.</dd> + <dt><code>open-quote</code> | <code>close-quote</code></dt> + <dd>These values are replaced by the appropriate string from the {{cssxref("quotes")}} property.</dd> + <dt><code>no-open-quote</code> | <code>no-close-quote</code></dt> + <dd>Introduces no content, but increments (decrements) the level of nesting for quotes.</dd> +</dl> + +<h2 id="Accessibility_concerns">Accessibility concerns</h2> + +<p>CSS-generated content is not included in the <a href="/en-US/docs/Web/API/Document_Object_Model/Introduction">DOM</a>. Because of this, it will not be represented in the <a href="/en-US/docs/Learn/Accessibility/What_is_accessibility#Accessibility_APIs">accessibility tree</a> and certain assistive technology/browser combinations will not announce it. If the content conveys information that is critical to understanding the page's purpose, it is better to include it in the main document.</p> + +<ul> + <li><a href="https://tink.uk/accessibility-support-for-css-generated-content/">Accessibility support for CSS generated content – Tink</a></li> + <li><a href="/en-US/docs/Web/Accessibility/Understanding_WCAG/Perceivable#Guideline_1.3_%E2%80%94_Create_content_that_can_be_presented_in_different_ways">Explanation of WCAG, Guideline 1.3 – MDN</a></li> + <li><a href="https://www.w3.org/TR/UNDERSTANDING-WCAG20/content-structure-separation-programmatic.html">Understanding Success Criterion 1.3.1 | W3C Understanding WCAG 2.0</a></li> +</ul> + +<h2 id="Formal_definition">Formal definition</h2> + +<p>{{cssinfo}}</p> + +<h2 id="Formal_syntax">Formal syntax</h2> + +<pre class="syntaxbox notranslate">{{csssyntax}}</pre> + +<h2 id="Examples">Examples</h2> + +<h3 id="Headings_and_quotes">Headings and quotes</h3> + +<p>This example inserts quotation marks around quotes, and adds the word "Chapter" before headings.</p> + +<h4 id="HTML">HTML</h4> + +<pre class="brush: html notranslate"><h1>5</h1> +<p>According to Sir Tim Berners-Lee, + <q cite="http://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>According to the Mozilla Manifesto, + <q cite="http://www.mozilla.org/en-US/about/manifesto/">Individuals + must have the ability to shape the Internet and + their own experiences on the Internet.</q> + Therefore, we can infer that contributing to the open web + can protect our own individual experiences on it. +</p></pre> + +<h4 id="CSS">CSS</h4> + +<pre class="brush: css notranslate">q { + color: blue; +} + +q::before { + content: open-quote; +} + +q::after { + content: close-quote; +} + +h1::before { + content: "Chapter "; /* The trailing space creates separation + between the added content and the + rest of the content */ +}</pre> + +<h4 id="Result">Result</h4> + +<p>{{EmbedLiveSample('Headings_and_quotes', '100%', 200)}}</p> + +<h3 id="Image_combined_with_text">Image combined with text</h3> + +<p>This example inserts an image before the link. If the image is not found, it inserts text instead.</p> + +<h4 id="HTML_2">HTML</h4> + +<pre class="brush: html notranslate"><a href="http://www.mozilla.org/en-US/">Mozilla Home Page</a></pre> + +<h4 id="CSS_2">CSS</h4> + +<pre class="brush: css notranslate">a::before { + content: url("https://mozorg.cdn.mozilla.net/media/img/favicon.ico") / " MOZILLA: "; + font: x-small Arial, sans-serif; + color: gray; +}</pre> + +<h4 id="Result_2">Result</h4> + +<p>{{EmbedLiveSample('Image_combined_with_text', '100%', 60)}}</p> + +<h3 id="Targeting_classes">Targeting classes</h3> + +<p>This example inserts additional text after special items in a list.</p> + +<h4 id="HTML_3">HTML</h4> + +<pre class="brush: html notranslate"><h2>Paperback Best Sellers</h2> +<ol> + <li>Political Thriller</li> + <li class="new-entry">Halloween Stories</li> + <li>My Biography</li> + <li class="new-entry">Vampire Romance</li> +</ol></pre> + +<h4 id="CSS_3">CSS</h4> + +<pre class="brush: css notranslate">.new-entry::after { + content: " New!"; /* The leading space creates separation + between the added content and the + rest of the content */ + color: red; +}</pre> + +<h4 id="Result_3">Result</h4> + +<p>{{EmbedLiveSample('Targeting_classes', '100%', 160)}}</p> + +<h3 id="Images_and_element_attributes">Images and element attributes</h3> + +<p>This example inserts an image before each link, and adds its <code>id</code> attribute after.</p> + +<h4 id="HTML_4">HTML</h4> + +<pre class="brush: html notranslate"><ul> + <li><a id="moz" href="http://www.mozilla.org/"> + Mozilla Home Page</a></li> + <li><a id="mdn" href="https://developer.mozilla.org/"> + Mozilla Developer Network</a></li> +</ul></pre> + +<h4 id="CSS_4">CSS</h4> + +<pre class="brush: css notranslate">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; +} +</pre> + +<h4 id="Result_4">Result</h4> + +<p>{{EmbedLiveSample('Images_and_element_attributes', '100%', 160)}}</p> + +<h3 id="Element_replacement">Element replacement</h3> + +<p>This example replaces an element's content with an image. You can replace the contents of an element with either a {{cssxref("<url>")}} or an {{cssxref("<image>")}} value. Content added with <code>::before</code> or <code>::after</code> will not be generated as the contents of the element have been replaced.</p> + +<h4 id="HTML_5">HTML</h4> + +<pre class="brush: html notranslate"><div id="replaced">Mozilla</div> +</pre> + +<h4 id="CSS_5">CSS</h4> + +<pre class="brush: css notranslate">#replaced { + content: url("https://mdn.mozillademos.org/files/12668/MDN.svg"); +} + +#replaced::after { /* will not show if element replacement is supported */ + content: " (" attr(id) ")"; +}</pre> + +<h4 id="Result_5">Result</h4> + +<p>{{EmbedLiveSample('Element_replacement', '100%', 200)}}</p> + +<h2 id="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 Content", "#content-property", "content")}}</td> + <td>{{Spec2("CSS3 Content")}}</td> + <td>Adds support for alt-text</td> + </tr> + <tr> + <td>{{SpecName("CSS2.1", "generate.html#content", "content")}}</td> + <td>{{Spec2("CSS2.1")}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + + + +<p>{{Compat("css.properties.content")}}</p> + +<h2 id="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/Web/CSS/Replaced_element">Replaced elements</a></li> + <li>{{Cssxref("::after")}}</li> + <li>{{Cssxref("::before")}}</li> + <li>{{Cssxref("::marker")}}</li> + <li>{{Cssxref("quotes")}}</li> + <li>{{cssxref("url()", "url()")}} function</li> +</ul> |