aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/css/width/index.html
blob: 5e09c751d912427c395ed472bdaab3badf0b1305 (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
---
title: width
slug: Web/CSS/width
tags:
  - Propiedad CSS
  - Referencia
translation_of: Web/CSS/width
---
<div>{{CSSRef}}</div>

<h2 id="Resumen">Resumen</h2>

<p>La propiedad <a href="/en-US/docs/Web/CSS">CSS</a> <strong><code>width</code></strong> especifica la anchura del area de contenido de un elemento. El <a href="/es/docs/Web/CSS/CSS_Box_Model/Introduction_to_the_CSS_box_model#content-area">área de contenido</a> está <em>dentro</em> del padding, borde, y margen del elemento.</p>

<p>Las propiedades {{cssxref("min-width")}} y {{cssxref("max-width")}} sobreescriben el valor de {{cssxref("width")}}.</p>

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

<h2 id="Sintaxis">Sintaxis</h2>

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

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

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

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

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

<dl>
 <dt><code>&lt;length&gt;</code></dt>
 <dd>Ver {{cssxref("&lt;length&gt;")}} para unidades disponibles.</dd>
 <dt><code>&lt;percentage&gt;</code></dt>
 <dd>Especificado con el tipo {{cssxref("&lt;percentage&gt;")}} como porcentaje de la anchura del bloque contenedor. Si la anchura del bloque contenedor depende de la anchura del elemento, la presentación resultante es indefinida.</dd>
 <dt><code>border-box </code>{{experimental_inline}}</dt>
 <dd>Si está presente, el valor {{cssxref("&lt;length&gt;")}}{{cssxref("&lt;percentage&gt;")}} precedente es aplicado a los límites del borde del elemento.</dd>
 <dt><code>content-box</code> {{experimental_inline}}</dt>
 <dd>Si está presente, el valor {{cssxref("&lt;length&gt;")}}{{cssxref("&lt;percentage&gt;")}} precedente será aplicado a los límites de contenido del elemento.</dd>
 <dt><code>auto</code></dt>
 <dd>El navegador calculará y seleccionará la anchura para el elemento especificado.</dd>
 <dt>fill {{experimental_inline}}</dt>
 <dd>Use el tamaño <code>fill-available</code> para elementos inline o block, según sea más apropiado para el modo de escritura.</dd>
 <dt><code>max-content</code> {{experimental_inline}}</dt>
 <dd>La anchura preferida intrínseca.</dd>
 <dt><code>min-content</code> {{experimental_inline}}</dt>
 <dd>La anchura mínima intrínseca.</dd>
 <dt><code>available</code> {{experimental_inline}}</dt>
 <dd>La anchura del bloque contenedor menos su margen horizontal, borde y padding.</dd>
 <dt><code>fit-content</code> {{experimental_inline}}</dt>
 <dd>El mayor entre:
 <ul>
  <li>la anchura mínima intrínseca</li>
  <li>la menor entre la anchura prefereida intrínseca y la anchura disponible</li>
 </ul>
 </dd>
</dl>

<h3 id="Sintaxis_formal">Sintaxis formal</h3>

{{csssyntax}}

<h2 id="Ejemplos">Ejemplos</h2>

<h3 id="Anchura_predeterminada">Anchura predeterminada</h3>

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

<pre class="brush:html">&lt;p class="goldie"&gt;The Mozilla community produces a lot of great software.&lt;/p&gt;</pre>

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

<h3 id="Píxeles_y_ems">Píxeles y ems</h3>

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

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

<pre class="brush: html">&lt;div class="px_length"&gt;Width measured in px&lt;/div&gt;
&lt;div class="em_length"&gt;Width measured in em&lt;/div&gt;</pre>

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

<h3 id="Porcentaje">Porcentaje</h3>

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

<pre class="brush: html">&lt;div class="percent"&gt;Width in percentage&lt;/div&gt;</pre>

<p>{{EmbedLiveSample('Percentage', '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;The Mozilla community produces a lot of great software.&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;The Mozilla community produces a lot of great software.&lt;/p&gt;</pre>

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

<h2 id="Especificaciones">Especificaciones</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Especificación</th>
   <th scope="col">Estado</th>
   <th scope="col">Comentarios</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS3 Box', '#the-width-and-height-properties', 'width')}}</td>
   <td>{{Spec2('CSS3 Box')}}</td>
   <td>Añade las palabras clave <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>Incluye <code>width</code> como propiedad que puede ser animada.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS2.1', 'visudet.html#the-width-property', 'width')}}</td>
   <td>{{Spec2('CSS2.1')}}</td>
   <td>Especifica a qué elementos es aplicable.</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS1', '#width', 'width')}}</td>
   <td>{{Spec2('CSS1')}}</td>
   <td>Definición inicial</td>
  </tr>
  <tr>
   <td>{{SpecName('CSS3 Sizing', '#width-height-keywords', 'width')}}</td>
   <td>{{Spec2('CSS3 Sizing')}}</td>
   <td>Añade nuevas palabras clave de tamaño para <code>width</code> y <code>height</code></td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilidad_de_navegadores">Compatibilidad de navegadores</h2>

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

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Característica</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Soporte 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>Capacidad de ser animada{{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> y <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ística</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 for Android</th>
  </tr>
  <tr>
   <td>Soporte 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>Capacidad de ser animada{{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> y <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 implementa una variante a este valor con el nombre <code>fill-available</code> a partir de 2013.</p>

<p>[2] Las versiones anteriores de WebKit implementaban una versión anterior de este valor con nombre <code>intrinsic</code>, pero implementan además <code>fit-content</code> desde la versión 6.1.</p>

<p>[3] Sin prefijo.</p>

<p>[4] Soporte a las antiguas palabras clave <code>intrinsic</code> y <code>min-intrinsic</code> de Webkit, pero removido en <a href="https://www.chromestatus.com/feature/5758434351775744">Chrome 48</a>.</p>

<h2 id="Véase_también">Véase también</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>