aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/css/used_value
diff options
context:
space:
mode:
authorFlorian Merz <me@fiji-flo.de>2021-02-11 14:49:58 +0100
committerFlorian Merz <me@fiji-flo.de>2021-02-11 14:49:58 +0100
commit68fc8e96a9629e73469ed457abd955e548ec670c (patch)
tree8529ab9fe63d011f23c7f22ab5a4a1c5563fcaa4 /files/pt-br/web/css/used_value
parent8260a606c143e6b55a467edf017a56bdcd6cba7e (diff)
downloadtranslated-content-68fc8e96a9629e73469ed457abd955e548ec670c.tar.gz
translated-content-68fc8e96a9629e73469ed457abd955e548ec670c.tar.bz2
translated-content-68fc8e96a9629e73469ed457abd955e548ec670c.zip
unslug pt-br: move
Diffstat (limited to 'files/pt-br/web/css/used_value')
-rw-r--r--files/pt-br/web/css/used_value/index.html114
1 files changed, 114 insertions, 0 deletions
diff --git a/files/pt-br/web/css/used_value/index.html b/files/pt-br/web/css/used_value/index.html
new file mode 100644
index 0000000000..18c48dedb5
--- /dev/null
+++ b/files/pt-br/web/css/used_value/index.html
@@ -0,0 +1,114 @@
+---
+title: Valor usado
+slug: Web/CSS/Valor_usado
+translation_of: Web/CSS/used_value
+---
+<div>{{cssref}}</div>
+
+<p>O <strong>valor usado</strong> de uma propriedade CSS é o valor final dessa propriedade depois de todos os cálculos terem sido executados.</p>
+
+<p>After the user agent has finished its calculations, every CSS property has a used value. The used values of dimensions (e.g., <code>width</code>, <code>line-height</code>) are in pixels. The used values of shorthand properties (e.g., background) are consistent with those of their component properties (e.g., <code>background-color</code>, <code>display)</code> and with <code>position</code> and <code>float</code>.</p>
+
+<p>For some properties, JavaScript can retrieve the used value through the <a href="/en-US/docs/DOM/window.getComputedStyle" style="text-decoration: none; color: rgb(4, 137, 183) !important; cursor: default;" title="en/DOM/window.getComputedStyle">window.getComputedStyle</a> method.</p>
+
+<h2 id="Detalhes">Detalhes</h2>
+
+<p>There are four steps to calculating any CSS property's final value. First, the <a href="/en-US/docs/CSS/specified_value" title="https://developer.mozilla.org/en/CSS/specified_value">specified value</a> is the result of cascading (choosing the most specific stylesheet rule that changes the property), <a href="/en-US/docs/CSS/inheritance" title="en/CSS/inheritance">inheritance</a> (using the same computed value as a parent if the property is inheritable), or using the default. Then, the <a href="/en-US/docs/CSS/computed_value" title="en/CSS/computed value">computed value</a> is calculated according to the specification (for example, a <code>span</code> with <code>position: absolute</code> will have its computed <code>display</code> changed to <code>block</code>). Then, layout is calculated (dimensions that are <code>auto</code> or percentages relative to a parent are replaced with pixel values), and the result is the <strong>used value</strong>.</p>
+
+<p>Finally, transformed according to the limitations of the local environment, the result is <a href="/en-US/docs/Web/CSS/actual_value">actual value</a>. The actual value is the used value after any approximations have been applied. For example, a user agent may only be able to render borders with integer pixel widths, and therefore have to approximate the computed width, or the user agent may be forced to use only black and white shades, instead of full color. These steps are calculated internally.</p>
+
+<p>JavaScript can read only the final used values with <a href="/en-US/docs/DOM/window.getComputedStyle" style="text-decoration: none; color: rgb(4, 137, 183) !important; cursor: default;" title="en/DOM/window.getComputedStyle">window.getComputedStyle</a>. This method may instead return computed values, depending on the property. The values it returns are generically called {{cssxref("resolved_value", "resolved values")}}).</p>
+
+<h2 id="Exemplo">Exemplo</h2>
+
+<p>Compute and show the used width of three elements (updates on resize):</p>
+
+<h3 id="HTML">HTML</h3>
+
+<pre class="brush: html">&lt;div id="no-width"&gt;
+ &lt;p&gt;No explicit width.&lt;/p&gt;
+ &lt;p class="show-used-width"&gt;..&lt;/p&gt;
+
+ &lt;div id="width-50"&gt;
+ &lt;p&gt;Explicit width: 50%.&lt;/p&gt;
+ &lt;p class="show-used-width"&gt;..&lt;/p&gt;
+
+ &lt;div id="width-inherit"&gt;
+ &lt;p&gt;Explicit width: inherit.&lt;/p&gt;
+ &lt;p class="show-used-width"&gt;..&lt;/p&gt;
+ &lt;/div&gt;
+ &lt;/div&gt;
+&lt;/div&gt;
+</pre>
+
+<h3 id="CSS">CSS</h3>
+
+<pre class="brush: css">#no-width {
+ width: auto;
+}
+
+#width-50 {
+ width: 50%;
+}
+
+#width-inherit {
+ width: inherit;
+}
+
+/* Make results easier to see: */
+div {
+ border: 1px solid red;
+ padding: 8px;
+}</pre>
+
+<h3 id="JavaScript">JavaScript</h3>
+
+<pre class="brush: js">function updateUsedWidth(id) {
+ var div = document.getElementById(id);
+ var par = document.querySelector(`#${id} .show-used-width`);
+ var wid = window.getComputedStyle(div)["width"];
+ par.textContent = `Used width: ${wid}.`;
+}
+
+function updateAllUsedWidths() {
+ updateUsedWidth("no-width");
+ updateUsedWidth("width-50");
+ updateUsedWidth("width-inherit");
+}
+
+updateAllUsedWidths();
+window.addEventListener('resize', updateAllUsedWidths);
+
+</pre>
+
+<h3 id="Resultado">Resultado</h3>
+
+<p>{{ EmbedLiveSample('Example', '80%', '372px') }}</p>
+
+<p> </p>
+
+<h2 id="Diferentes_valores_computados">Diferentes valores computados</h2>
+
+<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.7em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;">CSS 2.0 defined only <a href="/en-US/docs/CSS/computed_value" style="text-decoration: none; color: rgb(4, 137, 183) !important; cursor: default;" title="en/CSS/computed value">computed value</a> as the last step in a property's calculation. Then, CSS 2.1 introduced the distinct definition of used value. An element could then explicitly inherit a width/height of a parent, whose computed value is a percentage. For CSS properties that don't depend on layout (e.g., display, font-size, line-height), the computed values and used values are the same. These are the CSS 2.1 properties that do depend on layout, so they have a different computed value and used value: (taken from <a class="external" href="http://www.w3.org/TR/CSS2/changes.html#q36" title="http://www.w3.org/TR/CSS2/changes.html#q36">CSS 2.1 Changes: Specified, computed, and actual values</a>):</p>
+
+<ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.7em; margin-left: 25px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px;">
+ <li style="margin-bottom: 0.25em;">background-position</li>
+ <li style="margin-bottom: 0.25em;">bottom, left, right, top</li>
+ <li style="margin-bottom: 0.25em;">height, width</li>
+ <li style="margin-bottom: 0.25em;">margin-bottom, margin-left, margin-right, margin-top,</li>
+ <li style="margin-bottom: 0.25em;">min-height, min-width</li>
+ <li style="margin-bottom: 0.25em;">padding-bottom, padding-left, padding-right, padding-top</li>
+ <li style="margin-bottom: 0.25em;">text-indent</li>
+</ul>
+
+<h2 id="Especificações">Especificações</h2>
+
+<p><a class="external" href="http://www.w3.org/TR/CSS2/cascade.html#used-value" title="http://www.w3.org/TR/CSS2/cascade.html#used-value">CSS Level 2: Used Values</a></p>
+
+<h2 id="Veja_também">Veja também</h2>
+
+<ul>
+ <li><a href="/en-US/docs/CSS_Reference" title="CSS Reference">CSS Reference</a></li>
+ <li>{{ CSS_key_concepts() }}</li>
+ <li><a href="/en-US/docs/DOM/window.getComputedStyle" title="en/DOM/window.getComputedStyle">window.getComputedStyle</a></li>
+</ul>