2011-08-16 120 views
17

我有以下的自動生成的HTML:縮進多標籤

http://jsfiddle.net/BrV8X/

有什麼建議的方式,使用CSS,縮進標籤,以便有單選按鈕下的一些空白?

+0

如果可以換的每個輸入及標籤在一個div設置,你可以使用'顯示:表cell'有效地奠定了這些。那可能嗎? –

回答

35
label { 
    display: block; 
    margin-left: 20px; 
} 
input { 
    float: left; 
    margin-left: -20px; 
    margin-right: 7px; 
} 

這是小提琴:http://jsfiddle.net/hrfmt/。玩的價值。

編輯:

如果你需要支持的瀏覽器可以理解display: inline-block,用它來代替float

+0

您暗示可以使用'display:inline-block',但在答案中沒有提供示例。所以我添加了一個答案。 – aross

3

下面是如何做到這一點,而不訴諸浮動的例子。用這種方法你必須做一些有利差的魔法。

input { 
    display: inline-block; 
    margin-right: -100px; 
    /* The 2 below properties are just for "correct" vertical placement of the button. */ 
    margin-top: 5px; 
    vertical-align: top; 
} 
label { 
    display: inline-block; 
    margin-left: 100px; 
    margin-right: -100px; 
} 
div { 
    /* Just some spacing between the radio buttons. */ 
    margin-bottom: 5px; 
} 

http://jsfiddle.net/4osbp0mo/2/