使用css和javascript/jquery,我如何将我在页面上垂直显示的图像居中显示?让我画一张图。这就是我所拥有的。
-------
| |
| |
-------
----------
| |
| |
----------
------
| |
| |
------这就是我想要的
-------
| |
| |
-------
-----------
| |
| |
-----------
-----
| |
| |
-----发布于 2012-05-03 05:29:12
在居中的图像类上设置以下CSS:
display: block;
margin: 1em auto; /* the key here is auto on the left and right */发布于 2012-05-03 05:31:05
如果您将每个图像放在一个<div class="img">中,则将这些图像的样式设置为;
div.img{
margin: 0 auto;
}*根据需要调整宽度。
或者,您可以将<div class="img">的宽度设置为100%并使文本居中;
div.img{
width: 100%;
text-align: center;
}发布于 2012-05-03 05:32:11
一小段代码就能完成这项工作
display: inline-block;
margin: 1em auto;使用jQuery可以设置如下属性:
$("img#selector").css({
'display':'inline-block',
'margin' : '1em auto'
});https://stackoverflow.com/questions/10421992
复制相似问题