asp.net - 如何将表格内的单选按钮列表与表格的其余部分对齐
问题描述
我正在尝试使单选按钮列表与表格的其余部分对齐,即使您减小了浏览器窗口的大小。
<div>
<asp:Table ID="Table1" runat="server" style="width:100%" align="center">
<asp:TableRow runat="server" align="center">
<asp:TableCell runat="server" align="center">1</asp:TableCell>
<asp:TableCell runat="server" align="center">2</asp:TableCell>
<asp:TableCell runat="server" align="center">3</asp:TableCell>
<asp:TableCell runat="server" align="center">Result</asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server" align="center">
<asp:TableCell runat="server" align="center">
<asp:RadioButton ID="RadioButton1" runat="server" /></asp:TableCell>
<asp:TableCell runat="server" align="center">
<asp:RadioButton ID="RadioButton2" runat="server" /></asp:TableCell>
<asp:TableCell runat="server" align="center">
<asp:RadioButton ID="RadioButton3" runat="server" /></asp:TableCell>
<asp:TableCell runat="server" align="center"></asp:TableCell>
</asp:TableRow>
<asp:TableRow runat="server" align="center">
<asp:TableCell runat="server" align="center" RepeatColumns="3">
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
<asp:ListItem Value="3"></asp:ListItem>
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server" align="center"></asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
第二行我使用了 3 个单选按钮而不是单选按钮列表,并且即使在浏览器窗口的大小发生更改时也与第一行对齐,但第三行是我使用单选按钮列表的地方,它只是没有与表格的其余部分完全对齐。
这是一个打印屏幕以便更好地理解: https ://i.imgur.com/VjtU1cE.png
解决方案
前两行有四列,第三行只有两列。因此,要么在第三行再添加两列 (TableCells),要么将 ColumnSpan 属性设置为 3 到具有 RadioButtonList 要补偿的单元格。剩下的只是对齐和一些 CSS 的使用。
如果要添加空白单元格,请为 text 属性添加一个 HTML 空间,以使它们正确呈现。我猜你正在为表格单元格/边框使用 CSS。
因此,如果您只是将 ColumnSpan 添加到您所拥有的内容中:
<asp:TableRow runat="server" align="center">
<asp:TableCell runat="server" align="center" ColumnSpan="3"
RepeatColumns="3">
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
<asp:ListItem Value="3"></asp:ListItem>
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server" align="center"></asp:TableCell>
</asp:TableRow>
或者,您可以在现有内容中再添加两个空白单元格:
<asp:TableRow runat="server" align="center">
<asp:TableCell runat="server" align="left" CssClass="radioButtonCell"
RepeatColumns="3">
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
<asp:ListItem Value="3"></asp:ListItem>
</asp:RadioButtonList>
</asp:TableCell>
<asp:TableCell runat="server" align="center"> </asp:TableCell>
<asp:TableCell runat="server" align="center"> </asp:TableCell>
<asp:TableCell runat="server" align="center"> </asp:TableCell>
</asp:TableRow>
CSS:
请注意,这适用于我创建的代码段。您可能需要对此进行调整。在我的示例中,单选按钮太靠左了。
.radioButtonCell
{
padding-left:15px;
}
推荐阅读
- python - 如何正确使用在单元测试中返回值的每个测试设置函数?
- python - 如何使用 Python 选择性地漂亮打印 JSON 项目?
- javascript - 我不知道如何在子组件中使用反应导航
- javascript - Mongoose / Ejs - 如果我再次获取帖子,我将看不到我所做的评论,只有在我发表评论之后它才可见
- r - 如何在闪亮的应用程序中获取反应数据到 Radiant
- sql - SQL Server Management Studio,创建外键关系,获取不匹配现有主键或唯一约束
- javascript - 如何获取单元格并在 html 链接中返回
- python - How do I add custom css to a DataTable with a bokeh server application?
- javascript - 将选定的复选框值保存到数据库列
- jquery - 如何在 Jquery Sortable Plugin 上实现自动垂直滚动?