【问题标题】:Is there a way to know if the user is using a small device similar to flexbox using col-sm?有没有办法通过 col-sm 知道用户是否正在使用类似于 flexbox 的小型设备?
【发布时间】:2019-12-11 15:10:08
【问题描述】:

我想知道是否有办法知道用户是否在使用小型设备。如果用户使用小型设备或使用台式机,我希望我的导航菜单发生变化。我希望它类似于 col-sm

【问题讨论】:

标签: javascript html css sass bootstrap-4


【解决方案1】:

您可以针对响应式网站或不同尺寸的设备使用 CSS 媒体查询。您也可以根据移动方向使用 CSS。

<style>

    /* Extra small devices (phones, 600px and down) */
    @media only screen and (max-width: 600px) {  

       /* Your CSS Code for this device size */    

      }

    /* Small devices (portrait tablets and large phones, 600px and up) */
    @media only screen and (min-width: 600px) {  

       /* Your CSS Code for this device size */    

    }

    /* Medium devices (landscape tablets, 768px and up) */
    @media only screen and (min-width: 768px) {  

       /* Your CSS Code for this device size */    

    } 

    /* Large devices (laptops/desktops, 992px and up) */
    @media only screen and (min-width: 992px) {  

       /* Your CSS Code for this device size */    

    }      

    /* Extra large devices (large laptops and desktops, 1200px and up) */
    @media only screen and (min-width: 1200px) {

       /* Your CSS Code for this device size */ 

    }

   /* According to Mobile Orientation */
   @media only screen and (orientation: landscape) {   

       /* Your CSS Code for this device orientation */    

   }

  </style>

【讨论】:

    【解决方案2】:

    这就是 @media 查询在 CSS 中的用途。

    @media screen and (max-width:479px) {
        .navbar {
            // style of .navbar when screen is less than 479px
        }
    }
    
    @media screen and (min-width:480px) {
        .navbar {
            // style of .navbar when screen is 480px or larger
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-11-23
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      • 2010-10-31
      • 2021-04-09
      • 1970-01-01
      相关资源
      最近更新 更多