gpt4 book ai didi

c# - 如何对齐 Asp 单选按钮元素的列表项?

转载 作者:太空宇宙 更新时间:2023-11-04 06:19:09 24 4
gpt4 key购买 nike

单选按钮之间的间距固定宽度,文本向下。 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>

enter image description here

最佳答案

您可以这样做(注意将“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 或其他东西,我相信它仍然会被强制执行。您可以尝试添加 min-width:0 和可怕的 !important 规则(虽然这被认为是不好的做法)试图迫使它成为全能的统治者全部。

关于c# - 如何对齐 Asp 单选按钮元素的列表项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55662248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com