且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在第三个容器div内水平对齐2个div

更新时间:2023-02-06 19:10:40

这将使容器居中,并使两个div居中,同时将样式与实际内容:

This will center the container, and have the two divs within it centered, while separating the styles from the actual content:

HTML:

<div id="container">
    <div>Div 1</div>
    <div>Div 2</div>
</div>

CSS:

#container > div
{
    display: inline-block;
    border: solid 1px #000;
}
#container
{
    border: solid 1px #ff0000;
    text-align: center;
    margin: 0px auto;
    width: 40%;
}   

工作实例:

http://jsfiddle.net/JLjjK/