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

4 回答 4

1

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

浮动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>
于 2012-07-03T16:58:29.593 回答
0

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

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

于 2012-07-03T16:59:14.703 回答
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>
于 2012-07-03T16:59:20.210 回答
0

使用 RadioButtonList 控件,只需将 RepeatDirection 属性设置为 Horizo​​ntal:

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

于 2012-07-03T16:59:40.247 回答