Open taichi221228 opened 1 year ago
@taichi221228 Are container queries supported currently in linaria ?
@jsanthosh-godaddy I just checked in the development environment at hand and I don't think it is supported yet.
One thing that's missing is that a container query doesn't get the class name. For example, this css:
const Section = styled.section`
color: red;
@media (min-width: 5px) {
color: yellowgreen;
}
@container (min-width: 5px) {
color: cyan;
}
`;
Will produce:
.Section_s9q1p8m {
color: red;
}
@media (min-width: 5px) {
.Section_s9q1p8m {
color: yellowgreen;
}
}
@container (min-width: 5px) {
color: cyan;
}
Note that the .Section_s9q1p8m
class is injected into the @media
rule but not the @container
rule.
container queries seem to work for me in linaria 6:
const Div = styled.div`
width: 50vw;
height: 100vh;
container-type: size;
`;
const P = styled.p`
background-color: blue;
@container (min-width: 500px) {
background-color: tomato;
}
`;
function App() {
const [count, setCount] = useState(0);
return (
<Div>
<div>
<a href="https://vitejs.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<P>
Edit <code>src/App.tsx</code> and save to test HMR
</P>
</div>
<P className="read-the-docs">
Click on the Vite and React logos to learn more
</P>
</Div>
);
}
gives me this CSS:
.duwg8pj {
width:50vw; height:100vh; container-type:size;
}
.p1llctjr {
background-color:blue;
}
@container (min-width: 500px) {
.p1llctjr {
background-color:tomato;
}
}
sandbox: https://codesandbox.io/p/devbox/sharp-shirley-dpzjf3
Describe the enhancement
It is already compatible with most modern browsers. https://caniuse.com/css-container-queries
Motivation
Corresponds to
@container
and named container@container foo
with the same feel as@media
.summary of the container queries
properties
at-rule
length units
Possible implementations
Container queries are only truly valuable with CSS-in-JS! It improves expressiveness!
Related Issues