【问题标题】:How to align list item of Asp radio button element?如何对齐 Asp 单选按钮元素的列表项?
【发布时间】:2019-04-13 05:12:07
【问题描述】:

单选按钮之间的间隙具有固定宽度,并且文本向下。 asp:ListItem 不允许使用 divlabel 元素。我想根据文字设置asp:ListItem的宽度。我可以使用inspect source 编辑宽度,但我不知道如何为 Visual Studio 中的每个列表项指定宽度。我是 C# 的初学者,有人可以帮我怎么做吗?

<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal"
                 OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                    <asp:ListItem >Add</asp:ListItem>
                    <asp:ListItem>Clear all lines of code</asp:ListItem>
                    <asp:ListItem Selected="True">Do nothing</asp:ListItem>
                </asp:RadioButtonList>

【问题讨论】:

  • &lt;asp:ListItem class="whatever"&gt; 然后在 CSS 文件中 .whatever { width: 100px } 并将 100px 更改为适合您的任何值。如果你不懂CSS,请上网搜索。
  • 不允许“类”属性。我不能在 &lt;asp:ListItem&gt; 中使用任何 css 类
  • 抱歉,请使用CssClass 而不是class

标签: c# html css asp.net


【解决方案1】:

您可以这样做(注意将“CssClass”添加到您的 RadioButtonList [不是 ListItem]):

<asp:RadioButtonList ID="RadioButtonList1" runat="server" CssClass="myRadioList" RepeatDirection="Horizontal"
             OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
               <asp:ListItem >Add</asp:ListItem>
                <asp:ListItem>Clear all lines of code</asp:ListItem>
                <asp:ListItem Selected="True">Do nothing</asp:ListItem>
            </asp:RadioButtonList>

然后在 CSS 中:

.myRadioList input[type="radio"] { width: auto; }
.myRadioList label { font-weight:bold; width: auto; }

我不相信 ASP.NET 通常对单选按钮列表使用固定宽度。我在想你在某处设置了一些强制宽度的样式。可能是全局“标签”或“输入”样式。

如果不知道您的其他 CSS 是什么样子,就无法确定这是否能解决问题。例如,如果你有一个最小宽度集或其他东西,我相信它仍然会被强制执行。您可以尝试添加min-width:0 和可怕的!important 规则(尽管这被认为是不好的做法),试图强迫它成为万能的统治者。

【讨论】:

  • 非常感谢。是的,我没有注意到标签的全局样式。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-10
  • 2015-12-27
  • 2013-05-18
  • 2012-12-31
  • 2013-03-09
  • 2013-04-18
相关资源
最近更新 更多