asp.net - 有没有一种可靠的方法可以使标签与其控件顶部对齐?

标签 asp.net css label

我正在寻找一种直接的 css 解决方案,它将强制标签与它们在 asp 中的控件顶部对齐。例如:

<asp:Label runat="server" AssociatedControlID="cboBox" Text="Control Label" />
<asp:DropDownList runat="server" ID="cboBox" />

会出现这样的东西:

Control Label
[[[[[]]]]]]]]]]]]V

有什么想法吗?

最佳答案

将它们都包裹在一个 span 或 div 中:

<span class="field">
    <asp:Label runat="server" AssociatedControlID="cboBox" Text="Control Label" />
    <asp:DropDownList runat="server" ID="cboBox" />
</span>

然后:

.field label,
.field select
{
    display: inline-block;
    vertical-align: top;

    /* achieves same as inline-block for IE7 */
    *display: inline;
    *zoom: 1;
}

关于asp.net - 有没有一种可靠的方法可以使标签与其控件顶部对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9945632/

相关文章:

javascript - JS 滚动在我的网站上似乎不起作用

html - React Native - 输入顶部的标签

c# - jqgrid 没有选择样式

c# - 自动化测试工具

c# - ASP.Net Web 应用程序的插件

javascript - 使用 jQuery 在 Canvas 上绘制时更改光标?

javascript - 在 "onSelectedIndexChanged"上调用 jquery 函数

javascript - JQuery - 设置 css 和实际宽度/高度宽度一个函数

html - 标签在 Chrome 中消失

html - 如何将元素更靠近 html 标签