search

Home  >  Q&A  >  body text

How to choose appropriate CSS styles based on screen size/device

<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>
P粉529245050P粉529245050518 days ago587

reply all(2)I'll reply

  • P粉668019339

    P粉6680193392023-08-22 20:01:42

    Detection is automatic. You have to specify the css that can be used for each screen resolution:

    /* 对于所有屏幕,使用14px字体大小 */
    body {  
        font-size: 14px;    
    }
    /* 响应式,对于小屏幕,使用13px字体大小 */
    @media (max-width: 479px) {
        body {
            font-size: 13px;
        }
    }

    reply
    0
  • P粉145543872

    P粉1455438722023-08-22 18:57:54

    Use @media to query . They fit exactly that need. Here's an example of how they work:

    @media (max-width: 800px) {
      /* 在宽度等于或小于 800px 时显示的 CSS 代码放在这里 */
    }
    

    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.

    reply
    0
  • Cancelreply