align radio button one below the other

只谈情不闲聊 提交于 2019-12-13 04:18:46

问题


How do i have the radio button show one below the other like this?

                 Sex                 (button)Male
                                     (button) Female

Whatever i do, i get like this

                   Sex                 (button)Male
                   (button) Female

how do i do the margin left of the second radio button so that it is right below the first one?

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


You need to either group the items in side-by-side divs, or add additional spacing to align the second item.

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

or with padding:

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

You can also do it as a 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>



回答2:


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

You'll need a container div with a set width, and then two div's inside of it floated to the sides.




回答3:


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



回答4:


Use a RadioButtonList control and simply set the RepeatDirection property to Horizontal:

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



来源:https://stackoverflow.com/questions/11315570/align-radio-button-one-below-the-other

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!