2012-07-03 20 views
0

我如何讓單選按鈕顯示下面的一個像這樣?對齊另一個下方的單選按鈕

    Sex     (button)Male 
            (button) Female 

無論我做什麼,我得到這樣

    Sex     (button)Male 
        (button) Female 

我怎麼做離開第二個單選按鈕的邊緣,使其正下方的第一個?

  <label for="Sex">Sex:</label> 
      <asp:RadioButton ID="male" runat="server" GroupName="gender" 
        Text="Male"/> 
      <br/> 

      <asp:RadioButton ID="female" runat="server" GroupName="gender" Text="Female"/> 
+1

OT:您的HTML是不正確,標籤不指向任何東西。 –

回答

1

您需要在任一組並排側div S上的物品,或增加額外的間距對準的第二項。

浮動的div:

<div style="float: left;"> 
     <span>Sex:</label> 
</div> 
<div style="float: left;"> 
    <asp:RadioButton ID="male" runat="server" GroupName="gender" Text="Male"/> 
    <br/> 
    <asp:RadioButton ID="female" runat="server" GroupName="gender" Text="Female"/>   
</div> 
<div style="clear: both"></div> 

或填充:

<style> 
    .radioButtonPadding { 
     display: inline-block; 
     width: 45px; 
    } 
</style> 

<span class="radioButtonPadding">Sex:</label> 
<asp:RadioButton ID="male" runat="server" GroupName="gender" Text="Male"/> 
<br/> 
<span class="radioButtonPadding">&nbsp;</label> 
<asp:RadioButton ID="female" runat="server" GroupName="gender" Text="Female"/> 

你也可以做到這一點作爲一個RadioButtonList

<style> 
    .genderLabel { 
     float: left; 
     display: block; 
    } 
    .genderList { 
     float: left; 
    } 
    .clear { 
     clear: both; 
    } 
</style> 

<asp:Label id="genderLabel" runat="server" CssClass="genderLabel"  
    Text="Sex:" AssociatedControlID="genderList"/> 
<asp:RadioButtonList id="genderList" runat="server" CssClass="genderList"> 
    <asp:ListItem>Male</asp:ListItem> 
    <asp:ListItem>Female</asp:ListItem> 
</asp:RadioButtonList> 
<div class="clear"></div> 
+0

感謝您的回覆。我能夠使用單選按鈕列表並使其工作。由於在此之前我有一些span標籤,我無法使用div(最後一行)清除,但我可以使用
清除元素。 – cableload

0

使用RadioButtonList的

<asp:RadioButtonList ID="RadioButtonList1" 
    runat="server" AutoPostBack="True" CausesValidation="True" 
    onselectedindexchanged="RadioButtonList1_SelectedIndexChanged"> 
    <asp:ListItem Selected="True">male</asp:ListItem> 
    <asp:ListItem>female</asp:ListItem> 
</asp:RadioButtonList>