aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/css/fit-content/index.html
blob: fc3cceef6f4939684216aa9b4c82ef5a557a9d86 (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
---
title: fit-content()
slug: Web/CSS/fit-content
tags:
  - CSS
  - CSS Grid
  - Experimental
  - Función CSS
  - Layout
  - Referencia
  - Web
translation_of: Web/CSS/fit-content
---
<div>{{CSSRef}}{{SeeCompatTable}}</div>

<p>La función <a href="/en-US/docs/Web/CSS">CSS</a> <strong><code>fit-content()</code></strong> ajusta un tamaño dado a un tamaño disponible de acuerdo a la fórmula: <code>min(<var>maximum size</var>, max(<var>minimum size</var>, <var>argument</var>))</code>.</p>

<pre class="brush: css no-line-numbers">/* &lt;length&gt; values */
fit-content(200px)
fit-content(5cm)
fit-content(30vw)
fit-content(100ch)

/* &lt;percentage&gt; value */
fit-content(40%)
</pre>

<p>La función se puede usar como un tamaño de track en las propiedades de <a href="/en-US/docs/Web/CSS/CSS_Grid_Layout">CSS Grid</a>, donde el tamaño máximo es definido por <code><a href="/en-US/docs/Web/CSS/grid-template-columns#max-content">max-content</a></code> y el mínimo por <code><a href="/en-US/docs/Web/CSS/grid-template-columns#auto">auto</a></code>, el cual es calculado por "<code>auto"</code> (ej. <code><a href="/en-US/docs/Web/CSS/minmax">minmax(auto, max-content)</a></code>), excepto que el tamaño del track se restringe al argumento si éste es mas grande que el "auto" mínimo .</p>

<p>También puede usarse como tamaño de caja disponible para {{cssxref("width")}}, {{cssxref("height")}}, {{cssxref("min-width")}}, {{cssxref("min-height")}}, {{cssxref("max-width")}} y {{cssxref("max-height")}}, donde el tamañó máximo se refiere al tamaño máximo contenido y el mínimo al tamaño mínimo contenido.</p>

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

<p>Función que acepta un  <code>&lt;length&gt;</code> o un <code>&lt;percentage&gt;</code> como un argumento.</p>

<h3 id="Values">Values</h3>

<dl>
 <dt>{{cssxref("&lt;length&gt;")}}</dt>
 <dd>Una Longitud Absoluta.</dd>
 <dt>{{cssxref("&lt;percentage&gt;")}}</dt>
 <dd>Un porcentaje relativo al espacio disponible en los ejes dados.</dd>
 <dd>In grid properties it is relative to the inline size of the grid container in column tracks and to the block size of the grid container for row tracks. Otherwise it is relative to the available inline size or block size of the laid out box depending on the writing mode.</dd>
</dl>

<h3 id="Formal_syntax">Formal syntax</h3>

<pre class="syntaxbox">{{csssyntax}}</pre>

<h2 id="Ejemplo">Ejemplo</h2>

<h3 id="CSS">CSS</h3>

<pre class="brush: css; highlight[3]">#container {
  display: grid;
  grid-template-columns: fit-content(300px) fit-content(300px) 1fr;
  grid-gap: 5px;
  box-sizing: border-box;
  height: 200px;
  width: 100%;
  background-color: #8cffa0;
  padding: 10px;
}

#container &gt; div {
  background-color: #8ca0ff;
  padding: 5px;
}
</pre>

<h3 id="HTML">HTML</h3>

<pre class="brush: html">&lt;div id="container"&gt;
  &lt;div&gt;Item as wide as the content.&lt;/div&gt;
  &lt;div&gt;
    Item con más texto en él. Porque el contenido que es
    mas grande que el ancho máximo, está restringido a los
    300 pixeles.
  &lt;/div&gt;
  &lt;div&gt;Flexible item&lt;/div&gt;
&lt;/div&gt;</pre>

<h3 id="Result">Result</h3>

<p>{{EmbedLiveSample("Ejemplo", "100%", 200)}}</p>

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

<table class="standard-table">
 <thead>
  <tr>
   <th>Especificación</th>
   <th>Estado</th>
   <th>Comentario</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("CSS3 Sizing", "#valdef-width-fit-content-length-percentage", "fit-content()")}}</td>
   <td>{{Spec2("CSS3 Sizing")}}</td>
   <td>Define la función como el tamaño de caja disponible para {{cssxref("width")}}, {{cssxref("height")}}, {{cssxref("min-width")}}, {{cssxref("min-height")}}, {{cssxref("max-width")}} y {{cssxref("max-height")}}.</td>
  </tr>
  <tr>
   <td>{{SpecName("CSS Grid", "#valdef-grid-template-columns-fit-content", "fit-content()")}}</td>
   <td>{{Spec2("CSS Grid")}}</td>
   <td>Define la función cuando es usada como un tamaño de track.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p> </p>



<p>{{Compat("css.properties.grid-template-columns.fit-content")}}</p>

<p> </p>