[英]center images in fading background
I'm working on a fading slideshow and everything is working great but I just can't seem to get the image('s) centered... I guess/hope it's something small but it's driving me crazy that I just can't find the solution, hopefully someone can help me out! 我正在制作逐渐消失的幻灯片,并且一切都很好,但是我似乎无法使图像居中...我想/希望它很小,但是却让我发疯,我不能找到解决方案,希望有人可以帮助我!
.slider { position: absolute; top:0px; left:0px; width:100%; height:420px; overflow:hidden; } .slider img { width:2560px; height:100%; display:block; overflow:hidden; }
http://jsfiddle.net/DvK3p http://jsfiddle.net/DvK3p
Note I am using the ResponsiveSlides.js is a tiny jQuery plugin ( http://responsiveslides.com ) 请注意,我使用的是ResponsiveSlides.js,它是一个很小的jQuery插件( http://sensitiveslides.com )
To get your image centered, use 要使图像居中,请使用
margin-left: auto;
margin-right: auto;
But for this, you need the width of your element set: 但是为此,您需要元素集的宽度:
margin:0 auto; /* Same as above, but with margin-top and bottom set to 0 */
width: 200px; /* Example */
Or, you can't set width
& respect the original ratio of your picture without knowing either its height or width ; 或者,在不知道图片的高度或宽度的情况下,您无法设置其
width
并尊重其原始比例; these are things you have to do with JS. 这些是您必须与JS有关的事情。
Add this line to CSS .slider img
将此行添加到CSS
.slider img
margin: 0 auto;
But you need to work on it in the js too 但是您也需要在js中进行处理
Try changing position absolute to relative, set also a fixed width to container: slider and add to it margin: 0 auto. 尝试将绝对位置更改为相对位置,同时将container:滑块设置为固定宽度,并向其添加margin:0自动。
like this: 像这样:
.slider { position: relative;
top:0px; left:0px;
margin: 0 auto;
width:560px;
height:420px;
overflow:hidden;
}
.slider img { width:560px;
height:100%;
display:block;
overflow:hidden;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.