【问题标题】:Images on an owl carousel are zoomed in on mobile, how do I change it so that it displays all of the image on mobile?猫头鹰轮播上的图像在移动设备上被放大,如何更改它以在移动设备上显示所有图像?
【发布时间】:2021-05-31 16:50:33
【问题描述】:

这是它在桌面上的样子:

这是它在移动设备上的样子:

我有旋转木马的标准属性(没什么特别的,只是一个幻灯片)。我只是希望它在移动设备上缩放并显示整个图片,而不是放大随机部分。

HTML

<div class="home-banner">
    <div class="owl-carousel owl-theme home-slider">
        <div class="item pro_nw" style="background-image: url({{asset('public/frontend/images/slide1_v4.jpg')}});">
        </div>
        <div class="item pro_nw" style="background-image: url({{asset('public/frontend/images/slider-2.jpg')}});">
        </div>
        <div class="item pro_nw" style="background-image: url({{asset('public/frontend/images/slider-3.jpg')}});">
        </div>
    </div>
</div>

CSS

.home-slider{position: relative;}
.home-slider,
.home-slider .owl-stage-outer,
.home-slider .owl-stage-outer .owl-stage,
.home-slider .owl-stage-outer .owl-stage .owl-item,
.home-slider .owl-stage-outer .owl-stage .owl-item .item{height: 100%;}
.home-slider .owl-stage-outer .owl-stage .owl-item .item{
    position: relative;
    display:-webkit-box;
    display:-ms-flexbox;
    display:flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack:center;
    -ms-flex-pack:center;
    justify-content:center;
    -o-background-size: cover;
    -moz-background-size: cover;
    -webkit-background-size: cover;
    background-size: cover;
    background-repeat: no-repeat;
    background-position:center center;
    margin-bottom: 20px;
    min-height: 730px;
}

它必须是 CSS 中的属性之一(我认为)。我尝试了一些属性,但它以奇怪的方式扩展。

【问题讨论】:

    标签: javascript html css owl-carousel


    【解决方案1】:

    对于移动媒体查询,请确保更改背景大小以包含。 保持屏幕的原始尺寸比移动屏幕宽。

    【讨论】:

      【解决方案2】:

      首先将背景大小更改为包含。

      background-size: contain;
      

      然后检测设备的实际屏幕以根据自己的喜好调整图像大小

      @media screen and (max-width: 768px) {      
          .home-slider .owl-stage-outer .owl-stage .owl-item .item{      
              //size you wanted 
            //for example---
             width: 50%;
             height: 50%;
          
          } 
      } 
      
      

      【讨论】:

      • 我试过这个,将宽度和高度更改为不同的值,包括 100%。但这一直在发生imgur.com/a/6Sigp5N
      • 嗨,我认为你需要大量篡改 css 才能达到正确的大小,尝试更改 width: autoheight : 100vh 另外,我看到有人和你有同样的问题链接Height of Owl Carousel on phone 和下面这个由@Kurtis Rogers 爵士在同一页面上制作的codepen 是,我认为你想要为你的页面实现的方式Codepen
      • 非常感谢您的帮助,我会调查的 :)
      • 很高兴为您提供帮助 :)
      【解决方案3】:

      对于移动响应,根据屏幕使用媒体查询

      @media only screen and (max-width:600px) /* specify preferred width here*/
      {
      /*statement*/
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-10-03
        • 1970-01-01
        • 2023-04-07
        • 2020-10-05
        • 1970-01-01
        • 1970-01-01
        • 2015-05-17
        • 1970-01-01
        相关资源
        最近更新 更多