将单选按钮对齐在另一个下方

时间:2012-07-03 16:52:57

标签: html css css3 css-float

如何将单选按钮显示在另一个下方?

                 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"/>

4 个答案:

答案 0 :(得分:1)

您需要将项目分组并排div,或者添加额外的间距以对齐第二项。

浮动的divs:

<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>

答案 1 :(得分:0)

http://jsfiddle.net/charlescarver/fUvZR/1/

你需要一个具有设定宽度的容器div,然后其中的两个div浮动到两侧。

答案 2 :(得分: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>

答案 3 :(得分:0)

使用RadioButtonList控件并简单地将RepeatDirection属性设置为Horizo​​ntal:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.radiobuttonlist.repeatdirection.aspx