Html asp:CheckBoxList 的对齐和填充
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1681425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Alignment and padding for asp:CheckBoxList
提问by alpheus
I have an asp.net checkboxlist as follows:
我有一个 asp.net 复选框列表,如下所示:
<asp:CheckBoxList ID="CheckBoxList_Genres" runat="server" RepeatColumns="3">
<asp:ListItem Selected="True">Action</asp:ListItem>
<asp:ListItem Selected="True">Comedy</asp:ListItem>
<asp:ListItem Selected="True">Classics</asp:ListItem>
<asp:ListItem Selected="True">Documentary</asp:ListItem>
[...]
[...]
I have two problems: the text does not align with each checkbox, and in some browsers (notably Safari), there is no padding between the checkbox and the text (the text rides up against the checkbox). I am aware of the answer posted here: How to align checkboxes and their labels consistently cross-browsers
我有两个问题:文本不与每个复选框对齐,并且在某些浏览器(特别是 Safari)中,复选框和文本之间没有填充(文本与复选框对齐)。我知道这里发布的答案: 如何在跨浏览器中始终对齐复选框及其标签
However, I can't work out how to implement these styles in the asp:checkboxlist context; I know that a css style can be set for the checkboxlist, but do not think that this allows me to set separate styles for the "label" and the "checkbox". Help would be appreciated.
但是,我不知道如何在 asp:checkboxlist 上下文中实现这些样式;我知道可以为复选框列表设置 css 样式,但不要认为这允许我为“标签”和“复选框”设置单独的样式。帮助将不胜感激。
回答by tahdhaze09
You should be able to apply the same methods to the CssClass property of your CheckBoxList control as you would a regular checkbox.
您应该能够将与常规复选框相同的方法应用于 CheckBoxList 控件的 CssClass 属性。
Here is some CSS code I used to indent long text next to an ASP.net check box list:
这是我用来缩进 ASP.net 复选框列表旁边的长文本的一些 CSS 代码:
.chkChoice input
{
margin-left: -20px;
}
.chkChoice td
{
padding-left: 20px;
}
ASP.net:
ASP.NET:
<asp:CheckBoxList id="ChkWork" runat="server" TabIndex="2" CssClass="chkChoice">
回答by Xena Olson
In the properties of the check box list, switch the repeatlayout from flow to table. That will align the columns.
在复选框列表的属性中,将重复布局从流切换到表。这将对齐列。
回答by Shaahin
some of checkboxlist items, has label, for space between text and the item, for example checkbox, you have to give type of item in Css.
一些复选框列表项目,有标签,文本和项目之间的空间,例如复选框,你必须在 Css 中给出项目的类型。
Exlampel:
示例:
.myCheckBoxList label
{
padding-right: 5px;
}
and give che checkboxlist class like this:
并给 che checkboxlist 类,如下所示:
CssClass="myCheckBoxList"