jCarousel Lite - 水平和垂直居中图像
我在 Drupal 中使用了 jCarousel Lite,其中包含各种尺寸/长宽比的图像。我没有太多运气尝试将图像垂直和水平居中(即均匀间隔)。该插件要求图像位于
中。我尝试过 display:inline-block
、marginTop:50%
等等,其中大多数只是搞砸了轮播。
轮播发布于:http://carillontech.org/drupal/
谢谢!!
I have jCarousel Lite going in Drupal with images of various sizes/aspect ratios. I'm not having much luck trying to center the images vertically and horizontally (i.e. evenly-spaced). The plugin requires that the images be in a <ul><li><img ... /></li></ul>
. I've tried display:inline-block
, marginTop:50%
among other things, most of which just screw up the carousel.
The carousel is posted at: http://carillontech.org/drupal/
thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您已经在页面上使用了 jQuery,因此您可以执行此操作的一种方法是获取每个图像的图像高度,从轮播的高度中减去该高度,然后将该值的一半应用于图像或家长李。
像这样的事情:
您需要使用您正在使用的实际 id 调整#carousel,但它应该以这种方式工作。
One way you could do this, since you're using jQuery already on the page, is getting the image height for each image, subtracting that from the height of the carousel, and appling a top margin of half that value to the image or to the parent li.
Something like this:
You'd need to adjust #carousel with the actual id you're using, but it should work this way.
感谢您的提示。这有点逃避,但最简单的解决方案就是扩展图像画布,使它们的大小相同。如果背景颜色发生变化,我将不得不返回并在图像中更改它(因为 jpg 不透明),但至少它在每个浏览器上一致地工作(与 CSS 不同)。
Thanks for the hints. It's sort of a cop out, but the easiest solution has just been to extend the image canvases so that they're all the same size. If the background color ever changes, I'll have to go back and change it in the images (since jpg doesn't do transparency), but at least it works consistently on every browser (unlike CSS).