How to change CSS based on mobile device?

后端 未结 5 2151
一整个雨季
一整个雨季 2021-02-07 05:30

In the following example, I want to display only one div, depending on the device.

I\'m familiar with how to use @media to override a CSS cla

5条回答
  •  迷失自我
    2021-02-07 06:09

    Here's an example of how it can be done conditionally without javascript:

    //CSS
    .visibledevice {display:none;}
    .visibledesktop {display:display;}
    
    @media (max-width : 320px) {
        .visibledevice {display:block;}
        .visibledesktop {display:none;}
    }
    
    //in the page
    
    this displays for desktop and tablet
    this displays for mobile

提交回复
热议问题