How to use CSS container queries in talwind-css
Use container Queries in talwind-csss
Container queries enable you to apply styles to an element based on the size of the element’s container. If, for example, a container has less space available in the surrounding context, you can hide certain elements or use smaller fonts. Container queries are an alternative to media queries, which apply styles to elements based on viewport size or other device characteristics.
Step to configure container Queries in talwind-csss
Step 1:- Run npm command
npm install @tailwindcss/container-queries
Step 2:- Then add the plugin to your tailwind.config.js file: Tailwind.config.js
module.exports = {
theme: {
// ...
},
plugins: [
require("@tailwindcss/container-queries"),
// ...
],
};
Usage
<div class="@container">
<div class="@lg:underline">
<!-- This text will be underlined when the container is larger than `32rem` -->
</div>
</div>
You can use custom value also Example:
<div class="@container">
<div class="@[17.5rem]:underline"></div>
<!-- This text will be underlined when the container is larger than `17.5rem` -->
</div>
</div>
By default we ship with the following configured values:
Name | CSS |
---|---|
@xs | @container (min-width: 20rem /_ 320px _/) |
@sm | @container (min-width: 24rem /_ 384px _/) |
@md | @container (min-width:28rem /_ 448px _/) |
@lg | @container (min-width: 32rem /_ 512px _/) |
@xl | @container (min-width: 36rem /_ 576px _/) |
@2xl | @container (min-width: 42rem /_ 672px _/) |
@3xl | @container (min-width: 48rem /_ 768px _/) |
@4xl | @container (min-width: 56rem /_ 896px _/) |
@5xl | @container (min-width: 64rem /_ 1024px _/) |
@6xl | @container (min-width: 72rem /_ 1152px _/) |
@7xl | @container (min-width: 80rem /_ 1280px _/) |