简体   繁体   English

是否可以在html / css中定位手持式移动设备?

[英]is it possible to target handheld mobile devices in html/css?

I have a video in my html that I want only to show on desktop browsers because the difference in bandwidth i believe from desktop to mobile cripples the mobile browsers somewhat. 我的html中有一个视频,我只想在台式机浏览器上显示,因为我认为从台式机到移动设备的带宽差异在一定程度上削弱了移动浏览器。 Is there any logic in html, or css i can use to target mobile devices? 我可以使用html或CSS中的任何逻辑来定位移动设备吗?

here is my current html: 这是我当前的html:

  <div class="second-section">
    <video class="rocky" autoplay="true" loop>
      <source src="rocky_2.mp4" type="video/mp4">
      <source src="rocky_2.webm" type="video/webm">
    </video>
    <div class="overlay"></div>
  </div>

and my current css: 和我目前的CSS:

.second-section {
  position: relative;
  height: 100vh;
  background-color: #CD9B9B;
  background-position: center;
  background-size: cover;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
  text-align: center;
  overflow: hidden;
}
.rocky {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  min-width: 100%;
  min-height: 100%;
  width: auto;
  height: auto;
  background: transparent;
}

is there any media queries or any logic i can implement to make this video only display in desktop browsers? 我是否可以执行任何媒体查询或任何逻辑以使该视频仅在桌面浏览器中显示?

You can use following media query to not to display second_section div in mobile devices. 您可以使用以下媒体查询在移动设备中不显示second_section div。

In addition to that, you can show another video clip which optimized for mobile devices in the same media query 除此之外,您还可以在同一媒体查询中显示另一个针对移动设备优化的视频剪辑

@media (min-width:767px) {
    .second-section {
        display:block !important;
    }
    .second-section-mobile {
        display:none !important;
    }
}

@media (max-width: 766px) {
    .second-section {
        display:none !important;
    }
    .second-section-mobile {
        display:block !important;
    }
}

OPTIONALLY - You can use following lines to create more breakpoints 可选-您可以使用以下几行来创建更多断点

/*==========  Mobile First Method  ==========*/

/* Custom, iPhone Retina */ 
@media only screen and (min-width : 320px) {
}

/* Extra Small Devices, Phones */ 
@media only screen and (min-width : 480px) {

}

/* Small Devices, Tablets */
@media only screen and (min-width : 768px) {

}

/* Medium Devices, Desktops */
@media only screen and (min-width : 992px) {
}

/* Large Devices, Wide Screens */
@media only screen and (min-width : 1200px) {
}


/*==========  Non-Mobile First Method  ==========*/

/* Large Devices, Wide Screens */
@media only screen and (max-width : 1200px) {
}

/* Medium Devices, Desktops */
@media only screen and (max-width : 992px) {
}

/* Small Devices, Tablets */
@media only screen and (max-width : 768px) {
}

/* Extra Small Devices, Phones */ 
@media only screen and (max-width : 480px) {
}

/* Custom, iPhone Retina */ 
@media only screen and (max-width : 320px) {
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM