How to code CSS media queries targeting ALL mobile devices and tablets?

后端 未结 3 799
自闭症患者
自闭症患者 2020-12-02 10:09
@media only screen and (max-device-width : 640px) {
/* Styles */
}

@media only screen and (max-device-width: 768px) {
/* Styles */
}

This is what

3条回答
  •  鱼传尺愫
    2020-12-02 10:44

    You have your main desktop styles in the body of the CSS file (1024px and above) and then for specific screen sizes:

    @media all and (min-width:960px) and (max-width: 1024px) {
      /* put your css styles in here */
    }
    
    @media all and (min-width:801px) and (max-width: 959px) {
      /* put your css styles in here */
    }
    
    @media all and (min-width:769px) and (max-width: 800px) {
      /* put your css styles in here */
    }
    
    @media all and (min-width:569px) and (max-width: 768px) {
      /* put your css styles in here */
    }
    
    @media all and (min-width:481px) and (max-width: 568px) {
      /* put your css styles in here */
    }
    
    @media all and (min-width:321px) and (max-width: 480px) {
      /* put your css styles in here */
    }
    
    @media all and (min-width:0px) and (max-width: 320px) {
      /* put your css styles in here */
    }
    

    This will cover pretty much all devices being used - I would concentrate on getting the styling correct for the sizes at the end of the range (ie 320, 480, 568, 768, 800, 1024) as for all the others they will just be responsive to the size available.

    Also, don't use px anywhere - use em's or %

提交回复
热议问题