开发者

center div with adjacent one

Is it possible to construct a central div that has equal amounts of space on both sides, and another div that is always adjacen开发者_开发百科t to the big one, on it's exterior left side. I tried setting the width, but when I enlarge the page it isn't adjacent anymore.

Forgot to mention, the center div has sa fixed size.


Is this what you want:

CSS:

#left{
    width:25%;
    background:#cccccc;
    height:500px;
    float:left;
}
#center{
    width:50%;
    background:#adaddd;
    height:500px;
    margin-left:auto;
    margin-right:auto;
}

HTML

<div id="left"></div>
<div id="center"></div>

jsFiddle


In this fiddle center div has equal space on both sides. And central div also have an adjacent left div. Space between both (left and center) div is mostly same in all browser sizes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜