Comments (7)
Using :global
fixes this issue. For example:
&:global(:container(width >= 18em)) {}
However, it still seems to be failing when there is some class change on the element (adding a class .active
, for example). The CSS breaks in this case, as the container query disappears from the HTML element. Later, though, if the viewport is resized, everything goes back to normal.
from cq-prolyfill.
The PostCSS plugin converts the container query to an escaped class name, e.g. from :container(width < 10em)
to .\:container\(width\<10em\)
so it looks like a regular class name. Maybe it helps if you let the cq-prolyfill-plugin run after the css modules plugin.
If that doesn’t help, could you give me a quick example how I can reproduce this issue?
from cq-prolyfill.
@rulych is correct, using global works off the bat until something changes the class.
I tried moving the the css modules plugin to only process after but it doesn't work. I'll put the partial configs below:
webpack:
module: {
loaders: [
{
test: /\.css$/,
loader: 'style-loader!css-loader?modules!postcss-loader'
}
}
...
postcss: [
require('postcss-nested'),
require('cq-prolyfill/postcss-plugin')
]
component:
import React from 'react';
import styles from './styles.css';
export default ({ }) => (
<div className={styles['card-list']}>
<div className='res'>
<button>HELLO</button>
</div>
</div>
);
styles.css (with global workaround)
.card-list {
&:global(:container(width >= 18em)) {
background-color: red;
}
}
from cq-prolyfill.
I think the issue with using the :global is more a problem with using react. React sets the classes according to what css modules returns as class names, which does not seem to include the :container(...) but even if it did, the cq-prolyfill contains code that adds/removes classes to/from elements, which is generally very bad form for react.
from cq-prolyfill.
You could take a look at react-container-query-container from @VinSpee how it works there. Im not very familiar with React so I don’t know if it’s bad practice to change class names outside React code.
from cq-prolyfill.
Yeah alright. Which sucks because I really like cq-prolyfill. Here's to hoping it becomes a standard.
from cq-prolyfill.
Why was this issue closed when it was not resolved?
from cq-prolyfill.
Related Issues (20)
- Does cq-prolyfill inlined my style? HOT 1
- Minified cq-prolyfill.js file with gulp-concat doesn't work HOT 1
- Add stylesheet URL whitelist option
- Idea: ability to pre-parse CSS at build time
- Try to remove or reduce the FOUC problem HOT 10
- Add support for attribute selector based queries HOT 1
- Don’t run the script multiple times in the same frame HOT 1
- Use ResizeObserver HOT 8
- Use CSS Houdini (CSS Typed OM Level 1) to get the computed style HOT 1
- Check for max- and min-width and -height values
- In Safari with disabled cache container queries doesn't apply on first script load HOT 4
- Production as default, development/demo configurable HOT 1
- Improve getContainer, remove duplicated calls to getComputedStyle
- Raise minimum supported browser versions HOT 3
- Handling CSS Import Rule
- getContainer() delivers wrong element if element has size defined in percent HOT 8
- mixins.scss missing from package
- [IE11] Wrong Result if used with CSS Grid Layout HOT 2
- Don't work in Chrome 112 HOT 2
- Not working in Chrome anymore HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cq-prolyfill.