How to choose appropriate CSS styles based on screen size/device
P粉529245050
2023-08-21 21:50:42
<p>Bootstrap 3 has some nice CSS classes in the responsive utility that can hide or show certain blocks depending on the screen resolution<a href="http://getbootstrap.com/css/#responsive- utilities-classes">http://getbootstrap.com/css/#responsive-utilities-classes</a></p>
<p>I have some style rules in a CSS file that I want to apply or not apply based on the screen resolution. </p>
<p>What should I do? </p>
<p>I would compress all the CSS files into one file for production deployment, but if there is no other solution than using separate CSS files for different screen resolutions. </p>
Detection is automatic. You have to specify the css that can be used for each screen resolution:
Use
@media
to query . They fit exactly that need. Here's an example of how they work:This will only work on devices with a width equal to or less than 800px.
Learn more about media queries on the Mozilla Developer Network.