简体   繁体   English

将图像在Bootstrap滑块中水平和垂直居中

[英]centering an image in the Bootstrap slider both horizontally and vertically

First of all, here is a fiddle: http://jsfiddle.net/3CW4D/ 首先,这是一个小提琴: http : //jsfiddle.net/3CW4D/

I have the Bootstrap slider that may show different sized images. 我有可能显示不同尺寸图像的Bootstrap滑块。 What I'm trying to achieve is that they are all at most 570px in width and 379px in height. 我要达到的目标是,它们的最大宽度均为570px,高度最大为379px。

I've achieved this with 我已经做到了

.carousel{
width: 570px;
height: 379px;
}

.img-big{
max-width: 570px;
max-height: 379px;
margin: 0 auto;
}

for image 3, but image 2 in the slider is stuck at the top instead of being centered vertically. 对于图像3,​​但滑块中的图像2卡在顶部,而不是垂直居中。

How do I achieve this so they are centered no matter if they are higher or wider? 我如何做到这一点,以使它们居中,而不管它们是更高还是更宽?

Try to use the following css (your edited): 尝试使用以下CSS(已编辑):

.carousel .item{
    width: 570px;
    height: 379px;
}
.img-big{
    max-width: 570px;
    max-height: 379px;
    margin: 0 auto;
}
.align-to-middle {
    width: 570px;
    height: 379px;
    display:table-cell;
    vertical-align: middle;
}

And surround the image .img-big by ... which wraps the image and aligns it to middle. 并将图像.img-big包围在...周围,​​该图像将图像包裹并对齐到中间。

So the full code you could check here: http://jsfiddle.net/3CW4D/2/ 因此,您可以在此处查看完整的代码: http : //jsfiddle.net/3CW4D/2/

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

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