如果页面宽度缩小,水平居中4个图像并垂直堆叠?

时间:2013-03-28 00:24:27

标签: css html5 css3 centering

我目前在一个页面上有4张图片。我喜欢将它们水平居中,这样当页面收缩时它们会继续保持居中。如果页面缩小太多,我想垂直堆叠它们。

这是一个做我喜欢做的事的网站:http://www.wpexplorer.me/premium/photojax/

这是我的代码:

http://jsfiddle.net/NYcdS/

HTML

<div id="menu">
<img class ="blog" src="http://s18.postimg.org/il7hbk7i1/image.png">
<img class ="music" src="http://s18.postimg.org/4st2fxgqh/image.png">
<img class ="projects" src="http://s18.postimg.org/sxtrxn115/image.png">
<img class ="bio" src="http://s18.postimg.org/5xn4lb37d/image.png">

CSS

#menu {
    height: 300px;
    width: 1070px;
    background: #222;
    margin: 30px auto;
}

.blog {
    height: 300px;
    width: 250px;
}

.music {
    height: 300px;
    width: 250px;
}

.projects {
    height: 300px;
    width: 250px;
}

.bio {
    height: 300px;
    width: 250px;
}

1 个答案:

答案 0 :(得分:2)

听起来我觉得你想要的东西很简单:

#menu {
    text-align: center;
    margin: auto;
}

http://jsfiddle.net/5W2C2/3/

(使图像更小,更容易看到jsfiddle中发生了什么)

是吗?