帶有position:absolute
的元素總是從相關元素的常規流程中取出。
你可以做的是使用一個精靈的背景圖像。將你的複選框和你的圖像放在float:left
和float:right
divs中,或者將它們兩個都浮起來並在它們之間保留一個邊距並修改精靈的背景位置。如果你想,你也可以使用圖像,但我覺得使用精靈會更快。例如。
<div>
<div class='item'>
<div class='image'>
<img alt="" src="http://www.ahornblume.ch/images/img1.jpg" />
</div>
<div class='checkbox'>
<input name="product1[]" type="checkbox" value="skin" />skin
</div>
</div>
<div class='item'>
<div class='image'>
<img alt="" src="http://www.ahornblume.ch/images/img2.jpg" />
</div>
<div class='checkbox'>
<input name="product1[]" type="checkbox" value="face" />face
</div>
</div>
</div>
.item{
float:left;
width:auto;
}
.image{
float:left;
width:auto;
}
.checkbox{
float:right;
width:auto;
}
如果你想使用精靈,你可以給每個div則id
和定義背景位置,這取決於圖像複選框配對。
是的,我明白,但我的問題是沒有高度的複選框的容器的寬度.. 。如果複選框標籤很長,它應該展開。如果我指定容器的寬度,那麼一切正常......我只是認爲可能有更簡單的方法來實現這一點。 – Lorof
你應該設置一個固定的寬度。如果你不滿意,你將不得不使用JavaScript來計算寬度。 – mreq
如果你設置div正常顯示爲塊並給它們適當的'padding's(儘管每個塊都有所不同,它不應該是一種痛苦,因爲無論如何你都會計算'top'不得不)。希望你明白了。如果沒有,評論。 – mreq