我一直对我的图片有点问题。它实际上是一个jQuery幻灯片。图像的位置是绝对的,这使得它棘手的中心他们...jquery&CSS绝对中心位置
这很适合我
#slideshow IMG {
position:absolute;
top:0;
left:0;
z-index:8;
opacity:0.0;
width:100%;
text-align:center;
}
但宽度100%它使div的图像100%它的内部。一些图像比其他图像更薄,我只想让这些图像居中。宽度为100%时,可以伸展出薄的图像。
下面是HTML
<div class="contentImages">
<div id="slideshow">
<img src="upload/<?php echo $array['image'] ?>" height="200" class="active" />
<img src="upload/<?php echo $array['image2'] ?>" height="200" />
<img src="upload/<?php echo $array['image3'] ?>" height="200" />
</div></div>
和CSS
#slideshow {
position:relative;
height:200px;
overflow:hidden;
float:left;
width:250px;
}
.contentImages{
border:1px solid #CCC;
padding:10px;
margin:20px auto 0;
position:relative;
width:750px;
overflow:hidden;
}
我试图将文本对齐到幻灯片div的休息,但没有做任何事情我甚至试图将幻灯片div设置为绝对位置和文本对齐中心,但没有(有或没有宽度为100%或250像素)工作,它只显示图像的10%,它们是没有集中。
长话短说,我如何让我的图像居中而不会伸出薄薄的图像?
我希望这是有道理的。
谢谢。
----添加-----
我已经尝试通过使用此代码
$(window).bind('load', function() {
var img_width = $("#slideshow img").width();
$("#slideshow img").css("width", img_width);
alert(img_width);
});
去jQuery的溃败,但警告对所有图像的返回255,连薄的图像。
我调整我的CSS太
#slideshow IMG {
position:absolute;
top:0;
z-index:8;
opacity:0.0;
text-align:center;
}
你说你正在使用jQuery,所以你可以计算出图像的大小和位置应该是什么。如果这就是你所要求的,你想要的东西在纯CSS中是不可能的。 – 2012-04-04 17:27:53
你正在使用的jquery插件的名称是什么? – 2012-04-04 17:41:54
简单的jQuery幻灯片脚本 – user1274810 2012-04-04 17:50:54