我正在基於CSS創建我自己的Twitter Bootstrap單選按鈕。所選單選按鈕的視覺反饋基於input[type="radio"]:checked + span
。如何浮動動態div的彼此相鄰?
由於我的「按鈕」的內容可以變化,寬度是動態的。這導致問題對齊按鈕相鄰。我的JSfiddle我已經設置了50px的固定寬度。去除這個和按鈕在彼此之上。
任何人都可以指出我如何實現這一目標的正確方向?
這裏是我的代碼:
//HTML
<div class="button-group binary" data-toggle="buttons-radio">
<div class="radio-wrapper">
<input type="radio" class="active" name="status" value="1" />
<span class="background">Yes</span>
</div>
<div class="radio-wrapper">
<input type="radio" class="inactive" name="status" value="0" checked="checked" />
<span class="background">No</span>
</div>
</div>
//CSS
.button-group{
/*display: table;*/
display: block;
}
.radio-wrapper {
/*display: table-cell; */
display: inline-block;
position: relative;
height: 28px;
margin: 0;
width: 50px; /* I want this to be dynamic */
}
.radio-wrapper:first-child .background{
border-right: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.radio-wrapper:last-child .background{
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
input[type="radio"]{
position: absolute;
display: block;
height: 28px;
width: 100%;
z-index: 200;
cursor: pointer;
opacity: 0;
}
input[type="radio"]:checked + span {
background-color: #63B1DE;
color: #fff;
}
.background {
position: absolute;
z-index: 100;
height: 100%;
padding: 0 5px;
border: solid 1px #87A2B2;
background-color: #fff;
text-align: center;
line-height: 28px;
text-transform: uppercase;
}
老兄,你看起來很明顯!現在你在按鈕之間有空隙,但是通過使用表格/表格單元格可以解決這個問題。謝謝:) – Steven
對不起,對於jsFiddle :)我注意到它後,但認爲呃爲什麼不... – malkassem