Is there a solid way to top align labels to their controls?

删除回忆录丶 提交于 2019-12-08 13:02:45

问题


I'm looking for a straight forward css solution that will force labels to top align with their controls in asp. So for example:

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

Would appear something like:

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

Any ideas?


回答1:


Wrap them both in a span or div:

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

Then:

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

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



回答2:


You can try putting them in a container, and apply specific styling for spans within that container. The example below might need a little tweaking, but it should point you in the right direction:

div.container span {
    display: table-cell;
    vertical-align: top;
}
div.container input {
    display: table-cell;
    vertical-align:middle;
}

And then on the page:

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


来源:https://stackoverflow.com/questions/9945632/is-there-a-solid-way-to-top-align-labels-to-their-controls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!