ZeeCoder / container-query

A PostCSS plugin and Javascript runtime combination, which allows you to write container queries in your CSS the same way you would write media queries.
MIT License
139 stars 4 forks source link

Support for pseudo-selectors (ex, :hover) and pseudo-elements (ex, ::after) #14

Open ZeeCoder opened 7 years ago

ZeeCoder commented 7 years ago

This would probably require a lot more thought put into it, but it should be possible to apply styles only on hover / focus etc events.

Example: Increasing font-size on hover.

ZeeCoder commented 6 years ago

::before / ::after also should definitely be supported.

ahmadalfy commented 6 years ago

I would love to try and take a look at it.

ZeeCoder commented 6 years ago

Sounds good 👍

It might be a bit tricky, as what the plugin does is that instead of adding CSS to the DOM based on certain element conditions, it instead keeps track of all elements, and applies styles directly to them.

This means that to have support for pseudo-selectors, it would need to add / remove event listeners as conditions change.

If you want to give it a go, I can have a think of what the best solution would be, as it probably requires a refactor that either: 1) Allows the code to react to these condition changes somewhere in a smarter way, or 2) Replaces the current CSS-applying engine with one that injects actual CSS into the DOM, in which case implementing pseudo-selectors would be a no-brainer. 🤔

I have a gut-feeling the second option is probably the best one.

ZeeCoder commented 6 years ago

Actually, using something like styletron to handle css applying based on style objects would be the easiest, since then we wouldn't need to come up with a way to apply styles for only certain elements ourselves.

ahmadalfy commented 6 years ago

Thanks for the insights, I am currently examining the code and checking what can be done. Will keep your words in mind and update you with the results.

ZeeCoder commented 6 years ago

Sure, no worries 👍 Have you tried the package in a project already, or just planning to?

ahmadalfy commented 6 years ago

I am currently using the package in a project and it fits perfectly really. I've a valid use case for container query (or element query whatever people prefer to call it) and I was hit by the lack of support for the pseudo-classes 😆 and this is why I am seeing how to contribute 😄

ZeeCoder commented 6 years ago

Got it, thanks 👍

I thought someone would sooner or later want this feature. 😅