請注意:我已經看了幾個帖子SO和各種建議浮動並排2 div的一面,但他們都不似乎爲我工作。浮動DIV左,右按鍵
的建議摘要如下:
display: inline-block
float: left
他人蔘考overflow: hidden
,overflow: auto
各種實施方案。
一個工作過,我需要確立正確的div
:
position: absolute;
right: 0px
這是不理想的,因爲該按鈕將自身附着右側,忽略所有父容器的約束。
上面就是我想要什麼來實現的。
的左 div有藍色的背景。 右側 div包含按鈕。
我的代碼:
的Html
<div class="row">
<div class="display-inline-block float-left">
<h1>Your Order Schedule
<a id="editScheduleName" onclick="changeScheduleName()">
<img class="schedule-heading small-image" src=""images/icons/edit.png">
</a>
</h1>
</div>
<div class="display-inline-block float-right">
<input id="btnScheduleStatus" type="button" class="btn button-status btn-success" value="my button">
</div>
</div>
的CSS 注:使用自舉的基礎,我的大部分CSS的需要
.display-inline-block {
display: inline-block;
}
.schedule-heading {
position: relative;
}
.small-image {
width: 30px;
height: 30px;
margin-bottom: 5px;
}
.button-status {
width: 120px;
height: 50px;
font-weight: bold;
font-size: 18px;
}
幫助將非常讚賞
退房CSS'flexboxes'; 'display:flex; justify-content:space-between'可以解決你的問題。 –
你的行應該是100%的寬度,並且50%的子div都應用浮動左邊。 '.row {width:100%} .display-inline-block {width:50%,float:left}'不要忘記flex是Nandu Kalidindi建議的更好的選擇 – Muzammil