简体   繁体   English

在div中居中(水平和垂直)图像与jQuery幻灯片冲突

[英]Centering (horizontally and vertically) images within a div conflicting with jQuery slideshow

I know there are tons of posts about centering images within a div both vertically and horizontally. 我知道有很多关于将图片在div内垂直和水平居中的帖子。 That's not my problem. 那不是我的问题。 I was able to do that. 我能够做到这一点。

I'm building a portfolio website for my photographer friend using (a custom Wordpress theme). 我正在使用(自定义Wordpress主题)为我的摄影师朋友建立一个投资组合网站。 You can see it here: http://alexdebrabant.com/front Some pages of his site only have one picture, in which case I'm having no problem centering the image both vertically and horizontally within the .imgcontent div (using a combination of the display:table-cell, vertical-align:middle and text-align:center) You can see successful examples here: http://www.alexdebrabant.com/blog/emilia/ (full height and properly horizontally aligned) http://www.alexdebrabant.com/blog/trusst-2/ (full width and properly vertically aligned) 您可以在这里看到它: http : //alexdebrabant.com/front他的网站的某些页面上只有一张图片,在这种情况下,我可以毫无问题地将图像在.imgcontent div中垂直和水平居中(组合使用)表单元格,垂直对齐:中和的text-align:显示屏的中心)您可以在这里看到成功的例子: http://www.alexdebrabant.com/blog/emilia/ (全高和正常水平对齐) HTTP ://www.alexdebrabant.com/blog/trusst-2/ (完整宽度并正确垂直对齐)

However, some other pages have several pictures "wrapped" in a jQuery slideshow. 但是,其他一些页面在jQuery幻灯片中有几张“包裹”的图片。 On these pages, I can't seem to be able to center the images withing the div. 在这些页面上,我似乎无法将div与图像居中。 They align to the top left. 它们与左上方对齐。 You can see an example here: http://www.alexdebrabant.com/blog/divine-2/ (aligned top left of the div) 您可以在此处查看示例: http : //www.alexdebrabant.com/blog/divine-2/ (位于div的左上方)

I believe the issue is caused by the jQuery slideshow which, from what I understand, actually loads all the pictures but then hides all but one. 我相信问题是由jQuery幻灯片引起的,据我了解,该幻灯片实际上加载了所有图片,但随后隐藏了所有图片。

I was hoping someone might have a idea how to overcome this issue. 我希望有人可能对如何解决这个问题有所了解。 Thank you! 谢谢!

The issue is caused by the slideshow plugin, which applies position: absolute; top:0; left:0 此问题是由幻灯片插件引起的,该插件适用position: absolute; top:0; left:0 position: absolute; top:0; left:0 position: absolute; top:0; left:0 to the images, once there's more than one image. 一旦有一个以上的图像,则向图像position: absolute; top:0; left:0 This effectively cancels the alignment definitions assigned to the parent. 这有效地取消了分配给父对象的对齐方式定义。

Looking at the transition, the images blend into each other, so they have to be absolutely positioned (no other way to accomplish that). 观察过渡时,图像会相互融合,因此必须对其进行绝对定位(没有其他方法可以实现此目的)。

I think the following would work: Change 我认为以下方法会起作用:更改

<div class="imgcontent">
    <img.../>
    <img.../>
</div>

To: 至:

<div class="imgcontent">
    <div class="img-slide"><div class="img-cell"><img.../></div></div>
    <div class="img-slide"><div class="img-cell"><img.../></div></div>
</div>

With CSS: 使用CSS:

.img-slide, .img-cell {
    height: 660px;
    width: 880px;
}
.img-cell {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
}

Because the container ( .imgcontent ) dimensions are known, we apply them to the wrappers. 因为容器( .imgcontent )尺寸是已知的,所以我们将它们应用于包装器。 The img-slide wrapper will become absolutely positioned by the plugin, but its content should work as it does for a single image. img-slide包装器将完全由插件定位,但是其内容应该像对单个图像一样起作用。

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

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