-
Notifications
You must be signed in to change notification settings - Fork 22.5k
/
index.md
81 lines (55 loc) · 1.74 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
---
title: <length-percentage>
slug: Web/CSS/length-percentage
page-type: css-type
browser-compat: css.types.length-percentage
---
{{CSSRef}}
The **`<length-percentage>`** [CSS](/en-US/docs/Web/CSS) [data type](/en-US/docs/Web/CSS/CSS_Types) represents a value that can be either a {{Cssxref("length")}} or a {{Cssxref("percentage")}}.
## Syntax
Refer to the documentation for {{Cssxref("length")}} and {{Cssxref("percentage")}} for details of the individual syntaxes allowed by this type.
## Formal syntax
{{csssyntax}}
## Examples
### length-percentage examples
The following simple example demonstrates several properties that use `<length-percentage>` values.
#### HTML
```html
<p>You can use percentages and lengths in so many places.</p>
```
#### CSS
```css
p {
/* length-percentage examples */
width: 75%;
height: 200px;
margin: 3rem;
padding: 1%;
border-radius: 10px 10%;
font-size: 250%;
line-height: 1.5em;
/* length examples */
text-shadow: 1px 1px 1px red;
border: 5px solid red;
letter-spacing: 3px;
/* percentage example */
text-size-adjust: 20%;
}
```
#### Result
{{EmbedLiveSample('length-percentage_examples', '100%', 320)}}
### Use in calc()
Where a `<length-percentage>` is specified as an allowable type, this means that the percentage resolves to a length and therefore can be used in a {{cssxref("calc", "calc()")}} expression. Therefore, all of the following values are acceptable for {{cssxref("width")}}:
```css example-good
width: 200px;
width: 20%;
width: calc(100% - 200px);
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("<percentage>")}}
- {{cssxref("<length>")}}
- [CSS Values and Units](/en-US/docs/Web/CSS/CSS_Values_and_Units)