简体   繁体   English

如何在RadioButtonList asp.net控件的列表项之间添加空格?

[英]How to add space in-between the list items of a RadioButtonList asp.net Control?

Having spent some time googling the issue and trying a few things I can't seem to find a solution for this. 花了一些时间搜索问题并尝试了一些尝试,我似乎无法找到解决方案。 I have a RadioButtonList control that looks like: 我有一个RadioButtonList控件,看起来像:

<asp:RadioButtonList ID="rblCheck" runat="server" RepeatDirection="horizontal">
<asp:ListItem Value="red">Red</asp:ListItem>
<asp:ListItem Value="green">Green</asp:ListItem>
</asp:RadioButtonList>

Now when I look at it in a browser both the buttons are really close together. 现在,当我在浏览器中查看它们时,两个按钮实际上并在一起。 Is there any way for me to space them out? 我有什么办法可以将它们隔开吗? I tried margin-left css but that didn't sort it. 我尝试了左边距css,但是没有排序。 Any suggestions would be awesome. 任何建议都很棒。 Thanks. 谢谢。

You can do it in many ways. 您可以通过多种方式进行操作。 For instance you can set the CssClass property of RadioButtonList control. 例如,您可以设置RadioButtonList控件的CssClass属性。 Look below. 往下看。

<asp:RadioButtonList ID="rblCheck" runat="server" RepeatDirection="horizontal" CssClass="spaced">
<asp:ListItem Value="red">Red</asp:ListItem>
<asp:ListItem Value="green">Green</asp:ListItem>
</asp:RadioButtonList>

Then in your css declarations you can define the spaced class like this 然后在css声明中可以像这样定义spaced

.spaced input[type="radio"]
{
   margin-right: 50px; /* Or any other value */
}

Or if you wish to use different spacing for list items you can do it by specifying it with style attribute for each listitem this way 或者,如果你想使用不同的间距列表项,你可以通过指定它做到这一点style属性,每个listitem这样

<asp:RadioButtonList ID="rblCheck" runat="server" RepeatDirection="horizontal">
<asp:ListItem Value="red" style="margin-right:20px">Red</asp:ListItem>
<asp:ListItem Value="green" style="margin-right:30px">Green</asp:ListItem>
</asp:RadioButtonList>

Just add some CSS for it: 只需为其添加一些CSS:

input[type="radio"] {
 margin: 10px 10px;
}

How did you assign the CSS to that list? 您如何将CSS分配给该列表? The reason I ask is because if you tried to assign the CSS to the list by referencing the ID "rblCheck" that won't work (.NET will change the ID and append some numbers to the value). 我问的原因是因为如果您尝试通过引用无效的ID“ rblCheck”将CSS分配给列表(.NET将更改ID并将一些数字附加到值上)。

Try adding the CSS inline or giving the list a class to assign the CSS to. 尝试添加内联CSS或为列表提供将CSS分配给的类。

Just add some CSS for it 只需为其添加一些CSS

input[type=radio] {
    margin-left: 8px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何访问ASP.NET中的RadioButtonList项目? - How to access RadioButtonList items in ASP.NET? 在列表项之间添加空格,或者在ASP.NET下拉列表中更容易在触摸屏上选择项 - Add space between list items, or make items easier to select on touchscreens in ASP.NET dropdownlist 在RadioButtonList中选择一个项目,如何从asp.net中的数据库获取到ListBox的项目列表c# - Selecting an item in the RadioButtonList, how to get a list of items to a ListBox from database in asp.net c# 如何将一个项目添加到列表的末尾,中间有空项目? - How to add an Item to the end of a list with empty items in-between? 在 ASP.NET RadioButtonList 中向 LI 添加类 - Add Classes to LI in ASP.NET RadioButtonList 在asp.net上获取RadiobuttonList的ID列表 - Getting list of IDs for RadiobuttonList on asp.net 表中的C#ASP.Net RadioButtonList: <td> 边界也创建边界清单项 - C# ASP.Net RadioButtonList within table: <td> border also creating border arount LIST ITEMS 将一般的 ASP.NET 控件视为基于列表的控件(即 DropDownList、RadioButtonList 等) - Treat a general ASP.NET Control like a list-based control (i.e. DropDownList, RadioButtonList, etc.) asp.net radiobuttonlist不会选择索引 - asp.net radiobuttonlist will not selectindex 在ASP.NET中将具有正确ID的ListItem动态添加到RadiobuttonList - Dynamically add ListItem to RadiobuttonList with proper ID in ASP.NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM