You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The aspect ratio plugin exposes options for you to use. Here is the example for adding it to your project plugins
14
+
This plugin uses the `aspectRatio` key in your Tailwind config’s `theme` and `variants` objects to generate aspect ratio utilities. Here is an example:
15
15
16
16
```js
17
-
require('tailwindcss-aspect-ratio')({
18
-
ratios: {
19
-
'square': [1, 1],
20
-
'16/9': [16, 9],
21
-
'4/3': [4, 3],
22
-
'21/9': [21, 9],
23
-
}
24
-
})
17
+
// tailwind.config.js
18
+
{
19
+
theme: {
20
+
aspectRatio: { // defaults to {}
21
+
'square': [1, 1],
22
+
'16/9': [16, 9],
23
+
'4/3': [4, 3],
24
+
'21/9': [21, 9],
25
+
},
26
+
},
27
+
variants: {
28
+
aspectRatio: ['responsive'], // defaults to ['responsive']
29
+
},
30
+
plugins: [
31
+
require('tailwindcss-aspect-ratio')(),
32
+
],
33
+
}
25
34
```
26
35
27
-
This configuration would create the following classes:
36
+
This configuration would create the following classes, as well as their responsive variants:
28
37
29
38
```css
30
39
.aspect-ratio-square { padding-top: 100%; }
@@ -33,41 +42,6 @@ This configuration would create the following classes:
33
42
.aspect-ratio-21/9 { padding-top: 42.86%; }
34
43
```
35
44
36
-
The plugin accepts an object where the key is the suffix of the class name and the value is an array of width and height `[{width}, {height}]`.
45
+
The `aspectRatio` theme is an object where the key is the suffix of the class name and the value is an array of width and height `[{width}, {height}]`.
37
46
38
47
In the example above you can see that the key does not have to replicate the values, so if you prefer "nice names" you could have some like `'cinema': [21, 9]` or `'letterbox': [16,9]`.
39
-
40
-
As per the [tailwind plugin docs](https://tailwindcss.com/docs/plugins/) you are able to pass variants (responsive, hover, etc.) as a parameter.
41
-
42
-
```js
43
-
require('tailwindcss-aspect-ratio')({
44
-
ratios: {
45
-
'square': [1, 1],
46
-
'16/9': [16, 9],
47
-
'4/3': [4, 3],
48
-
'21/9': [21, 9],
49
-
},
50
-
variants: ['responsive', 'hover'],
51
-
})
52
-
```
53
-
54
-
Using the above should mean your plugins config looks something like this:
55
-
56
-
```js
57
-
// example plugins section of tailwind.js config file
0 commit comments