Skip to content

Commit 806591e

Browse files
committed
Improve documentation in readme
1 parent 9fd7608 commit 806591e

File tree

1 file changed

+50
-34
lines changed

1 file changed

+50
-34
lines changed

README.md

Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,47 +27,68 @@ module.exports = {
2727

2828
## Usage
2929

30+
Start by marking an element as a container using the `@container` class, and then applying styles based on the size of that container using the container variants like `@md:`, `@lg:`, and `@xl:`:
31+
3032
```html
31-
<!-- Container queries without a specific container name -->
3233
<div class="@container">
33-
<!-- Container query with a size of `lg` defined in your tailwind.config.js file -->
34-
<div class="@lg:underline"></div>
35-
<div class="@[1024px]:underline"></div>
34+
<div class="@lg:underline">
35+
<!-- This text will be underlined when the container is larger than `32rem` -->
36+
</div>
3637
</div>
38+
```
39+
40+
By default we provide [container sizes](#configuration) from `@xs` (`20rem`) to `@7xl` (`80rem`).
41+
42+
### Named containers
3743

38-
<!-- Container queries that apply for a defined container name -->
39-
<div class="@container/sidebar">
40-
<div class="@lg/sidebar:underline"></div>
41-
<div class="@[1024px]/sidebar:underline"></div>
44+
You can optionally name containers using a `@container/{name}` class, and then include that name in the container variants using classes like `@lg/main:underline`:
45+
46+
```html
47+
<div class="@container/main">
48+
<!-- ... -->
49+
<div class="@lg/main:underline">
50+
<!-- This text will be underlined when the "main" container is larger than `32rem` -->
51+
</div>
4252
</div>
4353
```
4454

45-
### Container types
55+
### Arbitrary container sizes
4656

47-
| Class | css |
48-
| --------------------------- | ------------------------------------------------------- |
49-
| `@container` | `container-type: inline-size;` |
50-
| `@container/sidebar` | `container-type: inline-size; container-name: sidebar;` |
51-
| `@container-normal` | `container-type: normal;` |
52-
| `@container-normal/sidebar` | `container-type: inline-size; container-name: sidebar;` |
57+
In addition to using one of the [container sizes](#configuration) provided by default, you can also create one-off sizes using any arbitrary value:
58+
59+
```html
60+
<div class="@container">
61+
<div class="@[17.5rem]:underline"></div>
62+
<!-- This text will be underlined when the container is larger than `17.5rem` -->
63+
</div>
64+
</div>
65+
```
66+
67+
### Removing a container
68+
69+
To stop an element from acting as a container, use the `@container-normal` class.
70+
71+
<div class="@container xl:@container-normal">
72+
<!-- ... -->
73+
</div>
5374

5475
## Configuration
5576

5677
By default we ship with the following configured values:
5778

58-
| Name | Value |
59-
| ----- | ------- |
60-
| `xs` | `20rem` |
61-
| `sm` | `24rem` |
62-
| `md` | `28rem` |
63-
| `lg` | `32rem` |
64-
| `xl` | `36rem` |
65-
| `2xl` | `42rem` |
66-
| `3xl` | `48rem` |
67-
| `4xl` | `56rem` |
68-
| `5xl` | `64rem` |
69-
| `6xl` | `72rem` |
70-
| `7xl` | `80rem` |
79+
| Name | CSS |
80+
| ------ | ------------------------------- |
81+
| `@xs` | `@container (min-width: 20rem)` |
82+
| `@sm` | `@container (min-width: 24rem)` |
83+
| `@md` | `@container (min-width: 28rem)` |
84+
| `@lg` | `@container (min-width: 32rem)` |
85+
| `@xl` | `@container (min-width: 36rem)` |
86+
| `@2xl` | `@container (min-width: 42rem)` |
87+
| `@3xl` | `@container (min-width: 48rem)` |
88+
| `@4xl` | `@container (min-width: 56rem)` |
89+
| `@5xl` | `@container (min-width: 64rem)` |
90+
| `@6xl` | `@container (min-width: 72rem)` |
91+
| `@7xl` | `@container (min-width: 80rem)` |
7192

7293
You can configure which values are available for this plugin under the `containers` key in your `tailwind.config.js` file:
7394

@@ -77,12 +98,7 @@ module.exports = {
7798
theme: {
7899
extend: {
79100
containers: {
80-
xs: '20rem',
81-
sm: '24rem',
82-
md: '28rem',
83-
lg: '32rem',
84-
xl: '36rem',
85-
// etc...
101+
`2xs`: '16rem',
86102
},
87103
},
88104
},

0 commit comments

Comments
 (0)