aboutsummaryrefslogtreecommitdiff
path: root/files/pt-br/web/css/width/index.html
blob: 0e47c4cabe2a4e1205a8512ae06b4aefe205dffc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
---
title: width
slug: Web/CSS/width
tags:
  - CSS
  - CSS Property
  - NeedsBrowserCompatibility
  - NeedsMobileBrowserCompatibility
  - PrecisaDeCompatibilidadeDeNavegador
  - PrecisadeCompatibilidadeMobile
  - Propriedade CSS
  - Reference
  - Referencia
translation_of: Web/CSS/width
---
<div>{{CSSRef}}</div>

<h2 id="Resumo">Resumo</h2>

<p>A propriedade <a href="pt-BR/docs/Web/CSS">CSS</a> <strong>width</strong> determina a largura da área de conteúdo de um elemento. A <a href="/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model#content-area">área de conteúdo</a> fica dentro do preenchimento, da borda, e da margem de um elemento.</p>

<p>As propriedades {{cssxref("min-width")}}{{cssxref("max-width")}} sobrescrevem o {{cssxref("width")}}.</p>

<p>{{cssinfo}}</p>

<h2 id="Sintaxe">Sintaxe</h2>

<pre class="brush:css">/* Valores de largura - &lt;length&gt; */
width: 300px;
width: 25em;

/* Valores percentuais - &lt;percentage&gt; */
width: 75%;

/* Valores com palavras-chave */
width: 25em border-box;
width: 75% content-box;
width: max-content;
width: min-content;
width: available;
width: fit-content;
width: auto;

/* Valores Globais */
width: inherit;
width: initial;
width: unset;
</pre>

<h3 id="Valores">Valores</h3>

<dl>
 <dt><code>&lt;length&gt;</code></dt>
 <dd>Veja {{cssxref("&lt;length&gt;")}} para possíveis unidades.</dd>
 <dt><code>&lt;percentage&gt;</code></dt>
 <dd>Especificado como {{cssxref("&lt;percentage&gt;")}} da largura do bloco contido. Se a largura do bloco contido depender da largura do elemento, o layout resultante é indefinido.</dd>
 <dt><code>border-box </code>{{experimental_inline}}</dt>
 <dd>Se presente, o precedente {{cssxref("&lt;length&gt;")}} ou {{cssxref("&lt;percentage&gt;")}} é aplicado para o border box do elemento.</dd>
 <dt><code>content-box</code> {{experimental_inline}}</dt>
 <dd>Se presente, o precedente {{cssxref("&lt;length&gt;")}} ou {{cssxref("&lt;percentage&gt;")}} é aplicado para o content box do elemento.</dd>
 <dt><code>auto</code></dt>
 <dd>O navegador irá calcular e selecionar a largura para o elemento específicado.</dd>
 <dt>fill {{experimental_inline}}</dt>
 <dd>Use o fill-available inline size ou fill-available block size, como um modo apropriado de escrita.</dd>
 <dt><code>max-content</code> {{experimental_inline}}</dt>
 <dd>Da largura interna preferível.</dd>
 <dt><code>min-content</code> {{experimental_inline}}</dt>
 <dd>Da largura interna mínina.</dd>
 <dt><code>available</code> {{experimental_inline}}</dt>
 <dd>Do bloco contendo a largura menos a margin horizontal, borda ou preenchimento.</dd>
 <dt><code>fit-content</code> {{experimental_inline}}</dt>
 <dd>A largura:
 <ul>
  <li>do comprimento interno mínimo.</li>
  <li>do menor comprimento interno preferível e da largura disponível.</li>
 </ul>
 </dd>
</dl>

<h3 id="Sintaxe_Formal">Sintaxe Formal</h3>

{{csssyntax}}

<h2 id="Exemplos">Exemplos</h2>

<h3 id="Largura_padrão">Largura padrão</h3>

<pre class="brush:css">p.douradinho {
  background: gold;
}</pre>

<pre class="brush:html">&lt;p class="douradinho"&gt;A comunidade Mozilla produz diversos softwares incríveis.&lt;/p&gt;</pre>

<p>{{EmbedLiveSample('Largura_padrão', '500px', '64px')}}</p>

<h3 id="Pixels_e_ems">Pixels e ems</h3>

<pre class="brush: css">.largura_px {
  width: 200px;
  background-color: red;
  color: white;
  border: 1px solid black;
}

.largura_em {
  width: 20em;
  background-color: white;
  color: red;
  border: 1px solid black;
}
</pre>

<pre class="brush: html">&lt;div class="largura_px"&gt;Largura medida com px&lt;/div&gt;
&lt;div class="largura_em"&gt;Largura medida com em&lt;/div&gt;</pre>

<p>{{EmbedLiveSample('Pixels_e_ems', '500px', '64px')}}</p>

<h3 id="Porcentagem">Porcentagem</h3>

<pre class="brush: css">.porcentagem {
  width: 20%;
  background-color: silver;
  border: 1px solid red;
}</pre>

<pre class="brush: html">&lt;div class="porcentagem"&gt;Largura em porcentagem&lt;/div&gt;</pre>

<p>{{EmbedLiveSample('Porcentagem', '500px', '64px')}}</p>

<h3 id="max-content">max-content</h3>

<pre class="brush:css;">p.maxgreen {
  background: lightgreen;
  width: intrinsic;           /* Safari/WebKit uses a non-standard name */
  width: -moz-max-content;    /* Firefox/Gecko */
  width: -webkit-max-content; /* Chrome */
}</pre>

<pre class="brush:html">&lt;p class="maxgreen"&gt;A comunidade Mozilla produz diversos softwares incríveis.&lt;/p&gt;</pre>

<p>{{EmbedLiveSample('max-content', '500px', '64px')}}</p>

<h3 id="min-content">min-content</h3>

<pre class="brush:css">p.minblue {
  background: lightblue;
  width: -moz-min-content;    /* Firefox */
  width: -webkit-min-content; /* Chrome */
}</pre>

<pre class="brush:html">&lt;p class="minblue"&gt;A comunidade Mozilla produz diversos softwares incríveis.&lt;/p&gt;</pre>

<p>{{EmbedLiveSample('min-content', '500px', '155px')}}</p>

<h2 id="Especificações">Especificações</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Especificação</th>
   <th scope="col">Status</th>
   <th scope="col">Comentários</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS3 Box', '#the-width-and-height-properties', 'width')}}</td>
   <td>{{Spec2('CSS3 Box')}}</td>
   <td>Adicionadas as palavras-chave <code>max-content</code>, <code>min-content</code>, <code>available</code>, <code>fit-content</code>, <code>border-box</code>, <code>content-box</code></td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Transitions', '#animatable-css', 'width')}}</td>
   <td>{{Spec2('CSS3 Transitions')}}</td>
   <td>Lista a largura como animável.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'visudet.html#the-width-property', 'width')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>Determina em qual elemento vai ser aplicado.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS1', '#width', 'width')}}</td>
   <td>{{Spec2('CSS1')}}</td>
   <td>Definição inicial</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Sizing', '#width-height-keywords', 'width')}}</td>
   <td>{{Spec2('CSS3 Sizing')}}</td>
   <td>Adiciona novas palavras-chave para largura e altura.</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilidade_dos_navegadores">Compatibilidade dos navegadores</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Características</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Suporte básico</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop("1.0")}}</td>
   <td>4</td>
   <td>3.5</td>
   <td>1.0 (85)</td>
  </tr>
  <tr>
   <td>Animação{{experimental_inline}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("16.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>max-content</code>{{experimental_inline}}</td>
   <td>{{CompatChrome(22.0)}} {{property_prefix("-webkit")}}<br>
    {{CompatChrome(46.0)}} [1]</td>
   <td>{{CompatGeckoDesktop("1.9")}}{{property_prefix("-moz")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>15 {{property_prefix("-webkit")}}</td>
   <td>2.0 (421) (<code>intrinsic</code> value)<br>
    6.1 {{property_prefix("-webkit")}}</td>
  </tr>
  <tr>
   <td><code>min-content</code>{{experimental_inline}}</td>
   <td>
    <p>{{CompatChrome(22.0)}} [4] {{property_prefix("-webkit")}}<br>
     {{CompatChrome(46.0)}} [1]</p>
   </td>
   <td>{{CompatGeckoDesktop("1.9")}} {{property_prefix("-moz")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>15 {{property_prefix("-webkit")}}</td>
   <td>2.0 (421) (<code>min-intrinsic</code> value)<br>
    6.1 {{property_prefix("-webkit")}}</td>
  </tr>
  <tr>
   <td><code>available</code>{{experimental_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop("1.9")}} {{property_prefix("-moz")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}<sup>[1]</sup></td>
  </tr>
  <tr>
   <td><code>fill-available</code>{{experimental_inline}}</td>
   <td>{{CompatChrome(22.0)}} {{property_prefix("-webkit")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>6.1 {{property_prefix("-webkit")}}</td>
  </tr>
  <tr>
   <td><code>fit-content</code>{{experimental_inline}}</td>
   <td>{{CompatChrome(22.0)}} [4] {{property_prefix("-webkit")}}<br>
    {{CompatChrome(46.0)}} [1]</td>
   <td>{{CompatGeckoDesktop("1.9")}} {{property_prefix("-moz")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>15 {{property_prefix("-webkit")}}</td>
   <td>6.1 {{property_prefix("-webkit")}}<sup>[2]</sup></td>
  </tr>
  <tr>
   <td><code>border-box</code> e <code>content-box</code>{{experimental_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>fill</code></td>
   <td>{{CompatChrome(46.0)}}</td>
   <td> </td>
   <td> </td>
   <td> </td>
   <td> </td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Características</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome para Android</th>
  </tr>
  <tr>
   <td>Suporte básico</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td>Animação{{experimental_inline}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop("16.0")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>max-content</code>{{experimental_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(46.0)}} [1]</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(46.0)}} [1]</td>
  </tr>
  <tr>
   <td><code>min-content</code>{{experimental_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(46.0)}} [1]</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(46.0)}} [1]</td>
  </tr>
  <tr>
   <td><code>available</code>{{experimental_inline}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>fill-available</code>{{experimental_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(46.0)}} [1]</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(46.0)}} [1]</td>
  </tr>
  <tr>
   <td><code>fit-content</code>{{experimental_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(46.0)}} [1]</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(46.0)}} [1]</td>
  </tr>
  <tr>
   <td><code>border-box</code> e <code>content-box</code>{{experimental_inline}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>fill</code></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(46.0)}}</td>
   <td> </td>
   <td> </td>
   <td> </td>
   <td> </td>
   <td>{{CompatChrome(46.0)}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] WebKit implementou uma variação deste valor sob o nome <em><code>fill-available</code></em> em Dezembro de 2013.</p>

<p>[2] Versões anteriores do WebKit implementaram uma versão anterior deste valore sob o nome <em><code>intrinsic</code></em>, mas implementam <em><code>fit-content</code></em> desde a versão 6.1 também.</p>

<p>[3] Não fixado.</p>

<p>[4] O antigo WebKit suporta as palavras-chave <em><code>intrinsic</code></em> e <em><code>min-intrinsic</code></em>, mas foi removido no <a href="https://www.chromestatus.com/feature/5758434351775744">Chrome 48</a>.</p>

<h2 id="Veja_também">Veja também</h2>

<ul>
 <li><a href="/en-US/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model">box model</a>, {{cssxref("height")}}, {{cssxref("box-sizing")}}, {{cssxref("min-width")}}, {{cssxref("max-width")}}</li>
</ul>