简体   繁体   English

猫头鹰旋转木马居中移动布局

[英]Owl Carousel Centering Mobile Layout

I have a web page formatted with jQuery mobile that utilizes Owl Carousel & Photoswipe and it is giving me trouble when viewed on mobile sizes.我有一个使用 Owl Carousel 和 Photoswipe 使用 jQuery mobile 格式化的网页,在移动尺寸上查看时给我带来了麻烦。 The problem is that when viewed on a portrait sized mobile phone (IPhone 5) the one image that is displayed is off center.问题是在纵向尺寸的手机(iPhone 5)上查看时,显示的一个图像偏离了中心。 I noticed that there is Javascript applying inline style to the ul with the class of .owl-carousel.owl-theme which sets the display to block.我注意到有 Javascript 将内联样式应用到带有 .owl-carousel.owl-theme 类的 ul 中,该类将显示设置为阻止。 If I switch this to inline while debugging the page in Mobile view with developer tools in Chrome the one image is correctly centered.如果我在使用 Chrome 中的开发人员工具在移动视图中调试页面时将其切换为内联,则一张图像会正确居中。 If I try to hard code this into the CSS then all images are stacked on top of one another and you can only click on one image (which is incorrect behavior since there are three images in the carousel/gallery).如果我尝试将其硬编码到 CSS 中,那么所有图像都会堆叠在一起,您只能单击一张图像(这是不正确的行为,因为轮播/图库中有三张图像)。

Does anyone know what my problem is, and how to solve it so that if viewed from a mobile device in portrait (when only one carousel image is displayed) the image is centered correctly on the page?有谁知道我的问题是什么,以及如何解决它,以便如果从移动设备纵向查看(当只显示一个轮播图像时)图像在页面上正确居中? I have other pages with similar CSS for the carousel (though not jQuery Mobile) and when viewed on a mobile device the behavior is correct, so I am stumped!我有其他具有类似 CSS 的轮播页面(虽然不是 jQuery Mobile),当在移动设备上查看时,行为是正确的,所以我很难过! Thank you for any help given!感谢您提供的任何帮助!

Try this CSS试试这个 CSS

CSS CSS

ul.owl-carousel{
padding:0;
text-align:center;
}

hope this helps..希望这可以帮助..

This is how I did it.我就是这样做的。 Based on Chandra Shekhar's answer, but it seems the plugin is using divs instead of ul now;基于 Chandra Shekhar 的回答,但似乎该插件现在正在使用 div 而不是 ul; also I added a mobile query.我还添加了一个移动查询。

@media only screen and (max-width: 450px) {
  div.owl-carousel {
    padding:0;
    text-align:center;
  }
}

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

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