admin管理员组文章数量:1122832
I woke up this morning with a thought.
Is it a good idea to split the different media queries in different files, check the width of the page in functions.php and then with an IF call the "correct" using wp_register_style
and wp_enqueue_style
?
I woke up this morning with a thought.
Is it a good idea to split the different media queries in different files, check the width of the page in functions.php and then with an IF call the "correct" using wp_register_style
and wp_enqueue_style
?
2 Answers
Reset to default 2There are no functions in wordpress that checks or determine screen sizes. These are all browser related stuff that has got nothing to do with wordpress. There are jquery functions that can maybe work, but again, this is not wordpress related. wp_is_mobile
can be used to load stuff conditionally for mobile phones, but then again, wp_is_mobile
don't have the logic determining screen sizes, it also can't differentiate between things like mobile phones and tablets.
Your solution here is to do it old school, using media queries in your main stylesheet as done in all of the default themes shipped with wordpress.
Closing off, I would most probably think that if there was such functions to determine screen sizes in wordpress, that it would be completely overrated and useless and time wasting just to load something simple like a stylesheet
Using media queries in your main stylesheet is OK but does not optimize the priority or even the ability to let HTTP/2 determine which files need to be loaded when a particular size screen is opened in the browser.
Example: wp_enqueue_style('html5blank', false, array(), false, 'all and (min-width: 1200px)');
would only load a stylesheet when browser is desktop.
To avoid loading large "main" stylesheet file you can split the calling of the files according to media: mobile, tablet, desktop, print and style.css.
Separating the CSS and specifying a media attribute value on each link tag allows the browser to prioritize what it currently needs.
Also, one large stylesheet inhibits regression tests on devices in that specific media query range. Compare that to the prospect of deploying the single bundled site.css file, an approach that would normally trigger a full regression test.
Good read: https://alistapart.com/article/mobile-first-css-is-it-time-for-a-rethink/
本文标签: functionsSplit Media Queries in different files
版权声明:本文标题:functions - Split Media Queries in different files! 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736298574a1930253.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论