- Notifications
You must be signed in to change notification settings - Fork 22.7k
/
Copy pathindex.md
155 lines (117 loc) · 3.53 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
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
---
title: exp()
slug: Web/CSS/exp
page-type: css-function
browser-compat: css.types.exp
---
{{CSSRef}}
The **`exp()`**[CSS](/en-US/docs/Web/CSS)[function](/en-US/docs/Web/CSS/CSS_Values_and_Units/CSS_Value_Functions) is an exponential function that takes an number as an argument and returns the mathematical constant `e` raised to the power of the given number.
The mathematical constant [`e`](<https://en.wikipedia.org/wiki/E_(mathematical_constant)>) is the base of natural logarithms, and is approximately `2.718281828459045`.
The `exp(number)` function contains a calculation which returns the same value as {{CSSxRef("pow", "pow(e, number)")}}.
## Syntax
```css
/* A <number> value */
width: calc(100px * exp(-1)); /* 100px * 0.367879441171442 = 36px */
width: calc(100px * exp(0)); /* 100px * 1 = 100px */
width: calc(100px * exp(1)); /* 100px * 2.718281828459045 = 217px */
```
### Parameters
The `exp(number)` function accepts only one value as its parameter.
-`number`
- : A calculation which resolves to a {{CSSxRef("number")}}. Representing the value to be raised by a power of `e`.
### Return value
Returns a non-negative {{CSSxRef("number")}} representing e<sup>number</sup>, which is the result of calculating `e` raised to the power of `number`.
- If `number` is `-Infinity`, the result is `0`.
- If `number` is `0`, the result is `1`.
- If `number` is `1`, the result is `e` (i.e., `2.718281828459045`).
- If `number` is `Infinity`, the result is `Infinity`.
## Formal syntax
{{CSSSyntax}}
## Examples
### Rotate elements
The `exp()` function can be used to {{CSSxRef("transform-function/rotate", "rotate")}} elements as it return a {{CSSxRef("number")}}.
#### HTML
```html
<divclass="box box-1"></div>
<divclass="box box-2"></div>
<divclass="box box-3"></div>
<divclass="box box-4"></div>
<divclass="box box-5"></div>
```
#### CSS
```css hidden
body {
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
gap: 50px;
}
```
```css
div.box {
width: 100px;
height: 100px;
background: linear-gradient(orange, red);
}
div.box-1 {
transform: rotate(calc(1turn* exp(-1))); /* 0.3678794411714423turn */
}
div.box-2 {
transform: rotate(calc(1turn* exp(-0.75))); /* 0.4723665527410147turn */
}
div.box-3 {
transform: rotate(calc(1turn* exp(-0.5))); /* 0.6065306597126334turn */
}
div.box-4 {
transform: rotate(calc(1turn* exp(-0.25))); /* 0.7788007830714049turn */
}
div.box-5 {
transform: rotate(calc(1turn* exp(0))); /* 1turn */
}
```
#### Result
{{EmbedLiveSample('Rotate elements', '100%', '200px')}}
### Scale headings by fixed ratio
The `exp()` function can be useful for strategies like CSS modular scale, which relates all the font-sizes on a page to each other by a fixed ratio.
#### HTML
```html
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
```
#### CSS
```css
h1 {
font-size: calc(1rem* exp(1.25)); /* 3.4903429574618414rem */
}
h2 {
font-size: calc(1rem* exp(1)); /* 2.718281828459045rem */
}
h3 {
font-size: calc(1rem* exp(0.75)); /* 2.117000016612675rem */
}
h4 {
font-size: calc(1rem* exp(0.5)); /* 1.6487212707001282rem */
}
h5 {
font-size: calc(1rem* exp(0.25)); /* 1.2840254166877414rem */
}
h6 {
font-size: calc(1rem* exp(0)); /* 1rem */
}
```
#### Result
{{EmbedLiveSample('Scale headings by fixed ratio', '100%', '300px')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{CSSxRef("pow")}}
- {{CSSxRef("sqrt")}}
- {{CSSxRef("hypot")}}
- {{CSSxRef("log")}}