Open Jeedey opened 10 years ago
You’re right, complex media queries is one of the last missing CSS3 features. I don’t think I’ll use this any time soon so if you really need it, you should code it yourself and send a pull request.
Finally I used some regex for parse this css, this css parser works great but it's not really good for website performance... Thank you anyway.
I think I’ll keep this issue open in case I do get around to implementing this.
@Jeedey would you mind sharing what you've got so far? Maybe I can help to find a fast solution based on your work.
Also had problems with media queries, but as they are per sé not important in my case i just clean the file of any media queries. Here are my cleaning approaches – maybe that helps others too:
$cssContent = preg_replace("/@media(\s)*\([^)]+\)(\s)*\{/i", "", $cssContent);
$cssContent = preg_replace("/\}(\s)*\}/i", "", $cssContent);
For your information this function parses css media queries:
https://github.com/recuweb-source/php-dom-scraper/blob/master/functions_dom_parser.php#L200
Since more and more css contains animation keyframes i had to update my media query replacement from above:
$code = preg_replace("/@media\s*\(([^)]+)\)\s*\{([^\{]+\{[^\}]+\})*\}/mi", "/* @media-begin($1) */\n$2\n/* @media-end($1) */\n", $code);
This wraps the media query with comments /* media-begin([condition]) */
and the corresponding end tag.
Any (partial?)progress with this 3 year old issue? I'd like to parse Foundation and "wrap" it under specific selector but it uses media queries a lot.
-
Maybe this could be of some help https://github.com/crossjoin/Css/tree/master/src/Crossjoin/Css/Format/Rule/AtMedia
@ivanjaros I’m not currently actively working on new features for the project. But I’m very much maintaining it so if you want to work on this and open a pull-request I’ll do my best to get it merged.
I try to parse a last Boostrap Css but i got an error to Sabberworm/CSS/Parser.php at line 171. Maybe it's can parse this line :
@media (min-width: 768px) {.lead {font-size: 21px;}}
Any idea?Thanks