-
Notifications
You must be signed in to change notification settings - Fork 22.7k
/
Copy pathindex.md
110 lines (81 loc) · 1.96 KB
/
index.md
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
---
title: max-content
slug: Web/CSS/max-content
page-type: css-keyword
browser-compat: css.properties.width.max-content
---
{{CSSRef}}
The `max-content` sizing keyword represents the maximum {{glossary("intrinsic size")}} of the content. For text content this means that the content will not wrap at all even if it causes overflows.
The {{cssxref("interpolate-size")}} property and {{cssxref("calc-size()")}} function can be used to enable animations to and from `max-content`.
## Syntax
```css
/* Used as a length */
width: max-content;
inline-size: max-content;
height: max-content;
block-size: max-content;
/* used in grid tracks */
grid-template-columns: 200px 1fr max-content;
```
## Examples
### Using max-content for box sizing
#### HTML
```html
<div id="container">
<div class="item">Item</div>
<div class="item">
Item with more text in it which will overflow the fixed width box.
</div>
</div>
```
#### CSS
```css
#container {
background-color: #8cffa0;
padding: 10px;
width: 200px;
}
.item {
width: max-content;
background-color: #8ca0ff;
padding: 5px;
margin-bottom: 1em;
}
```
#### Result
{{EmbedLiveSample("Using_max-content_for_box_sizing", "100%", 200)}}
### Sizing grid columns with max-content
#### HTML
```html
<div id="container">
<div>Item</div>
<div>Item with more text in it.</div>
<div>Flexible item</div>
</div>
```
#### CSS
```css
#container {
display: grid;
grid-template-columns: max-content max-content 1fr;
grid-gap: 5px;
box-sizing: border-box;
height: 200px;
width: 100%;
background-color: #8cffa0;
padding: 10px;
}
#container > div {
background-color: #8ca0ff;
padding: 5px;
}
```
#### Result
{{EmbedLiveSample("Sizing_grid_columns_with_max-content", "100%", 200)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- Related sizing keywords: {{cssxref("min-content")}}, {{cssxref("fit-content")}}
- [CSS box sizing](/en-US/docs/Web/CSS/CSS_box_sizing) module