html - 在 div 中居中图像的中间部分

标签 html css owl-carousel

图像比周围的 div 宽。 这是给机动部队的。 div中的图像 宽度:自动;并且持有它的 div 一样宽 作为可见区域。所以如果 div 是 500px 图片可能有 1000 像素左右的差异。但我想要 仅显示图像的中间部分。

我使用的是旧版本的 OWL Carousel v1.3.3

   <div id="custom-owl-slider" class="owl-slide" data-scroll-speed="2">
                <div class="item">
                    <img src="images/slider/IMG_3455.png" alt="">
                </div>
                 <div class="item">
                    <img src="images/slider/IMG_771.JPG" alt="">
                </div>
                <div class="item">
                    <img src="images/slider/IMG_321.JPG" alt="">
                </div>
                <div class="item">
                    <img src="images/slider/IMG_344.jpeg" alt="">
                </div>  
                <div class="item">
                    <img src="images/slider/IMG_563.jpeg" alt="">
                </div>   
                <div class="item">
                    <img src="images/slider/IMG_135.jpeg" alt="">
                </div>
            </div>

谢谢!

修复了以下问题:

#custom-owl-slider .owl-item  {
    display: flex !important;
    justify-content: center !important;
    height: auto; /* or other desired height */
    overflow: hidden !important;
}

#custom-owl-slider .owl-item img {
    flex: none !important; /* keep aspect ratio */
}

最佳答案

为 img 中间试试这个

.item > img {
    text-align: center;
    overflow: hidden;
}

PD:如果你愿意,这段代码应该适合 div 上的图像

.item > img{
    width: 100%;
}

关于html - 在 div 中居中图像的中间部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48670425/

相关文章:

html - ngx-owl-carousel 单个元素占用所有宽度的情况

具有 a 类但不具有 b 类的 CSS 选择器

javascript - owl-carousel box-shadow 添加白色边框

html - 是否有点击 div 的代码?

html - 可以在 :focus? 上设置其他元素的样式

html - Bootstrap 容器、行和列的使用

javascript - 增加一个 div 数据值,然后在 coffeescript 中再次设置它

javascript - 使用 laravel、vue.js 和 axios 删除 owl 幻灯片

html - 如何在 Bootstrap 3 中使导航栏元素具有固定宽度

html - 4 列 - 固定流体-流体-流体