如何使两个div并排浮动?

时间:2013-08-30 11:33:31

标签: html css

我一直试图让两个div并排浮动(即sliderdiv和main-search)但似乎无法得到它。同样的小提琴:http://jsfiddle.net/Ar99F/1/

标记式

<div id="homecontent" class="container">
    <div id="homecontent-mid" class="row rounded">
        <div id="homebanner" class="rounded">
            <div class="sliderdiv">Content Goes Here</div>
            <div class="main-search">Search Content Goes Here</div>
        </div>
    </div>
</div>

CSS

#homecontent {
    background: url("images/content-bg.png") repeat-x scroll 0 0 #FAFAFA;
    position: relative;
}

#homecontent-mid {
    background: url("images/bg-stage.png") repeat-y scroll right top #FFFFFF;
    border: 1px solid #BDBCBD;
    min-height: 100%;
    outline: medium none;
    top: -40px;
}

#homebanner {
    background: url("images/bg-stage-shade.png") repeat-x scroll 0 0 transparent;
    padding-right: 20px;
    position: relative;
}

.rounded {
    border-radius: 10px 10px 10px 10px;
}

.sliderdiv {
    background: none repeat scroll 0 0 red;
    float: right;
}

.main-search {
    background: none repeat scroll 0 0 #FFFFFF;
    border: medium solid #D51386;
    clear: both;
    float: left;
    overflow: hidden;
    padding: 20px 10px;
}

请帮助

3 个答案:

答案 0 :(得分:17)

看看 here 。 只需将float: left添加到其中,然后移除clear: both

答案 1 :(得分:2)

将<{1}}添加到您的包装器中以完成设计并移除overflow:hidden,您需要将clear:both;放在第一项而不是两者

<强> UPDATED FIDDLE

答案 2 :(得分:0)

喜欢这个

<强> DEMO

<强> CSS

#homecontent {
    background: url("images/content-bg.png") repeat-x scroll 0 0 #FAFAFA;
    position: relative;
}
#homecontent-mid {
    background: url("images/bg-stage.png") repeat-y scroll right top #FFFFFF;
    border: 1px solid #BDBCBD;
    min-height: 100%;
    outline: medium none;
    top: -40px; 
    display:table;
}
#homebanner {
    background: url("images/bg-stage-shade.png") repeat-x scroll 0 0 transparent;
    padding-right: 20px;
    position: relative;

}
.rounded {
    border-radius: 10px 10px 10px 10px;
}
.sliderdiv {
    background: none repeat scroll 0 0 red;

    display:table-cell;
}
.main-search {
    background: none repeat scroll 0 0 #FFFFFF;
    border: medium solid #D51386;
    clear: both;
    display:table-cell;
    overflow: hidden;
    padding: 20px 10px;
}