可能重复:
居中一个div,同时将另一个div浮动到右侧?
Centering one div while another div is floated to the right?
我正在尝试将container1居中,并将container2浮动到其右侧,使其略微溢出页面:
示例:http://i.imgur.com/JHkfn.jpg
不幸的是,正如您可以在网站模型(下面的链接)中看到的那样,container2跳到了container1的下方和右侧。
网站模型: http://ad313.samrandolphdesign.com/
CSS:
#container1 {
margin: auto;
background-color: #FFF;
width: 80%;
height: 100%;
max-width: 600px;
padding-bottom: 15px;
display: block;
}
#container2 {
background-color: #CC9900;
max-width: 600px;
width: 80%;
height: 100%;
padding-top: 60px;
padding-bottom: 50px;
text-align: center;
float: right;
display: block;
}
float
相比,我更喜欢inline-block
,但如果必须支持IE8或更低版本,则会出现问题。不幸的是,这些浏览器不支持inline-block
。 - Jared Farrish