4

我如何将 2 个标签与底部对齐对齐。如果一个标签有多行,则它旁边的标签将从顶部出现。我可以将它与底部对齐吗?

http://jsfiddle.net/ghkJC/3/

<div class="field">
  <div class="label">labl 1:</div>
  <div class="value">Some text</div>
  <br />
  <br />
</div>

<div class="field">
  <div class="label">this is a really really long label:</div>
  <div class="value">right after":" from previous label</div>
  <br />
</div>

.label {
    background: purple;
    float: left;      
    width: 100px;
    display: inline;
    vertical-align: 500px;

}

.value {
    background: red;
    width: 300px;
    float: right;

}

非常感谢 :)

4

3 回答 3

9

以下是一些供您选择的选项:

  1. 使用display:inline-block

    .label {
        background: purple;
        width: 100px;
        display: inline-block;
    }
    .value {
        background: red;
        width: 300px;
        display: inline-block;
        vertical-align: bottom;
    }
    

    演示小提琴

  2. 使用display:tabletable-cell

    .field {
        display: table;
    }
    .label,.value{
        display: table-cell;
    }
    .label {
        background: purple;
        min-width: 100px;
    }
    .value {
        background: red;
        width: 100%;
        vertical-align: bottom;
    }
    

    演示小提琴

  3. 采用position:absolute

    .field {
        position: relative;
    }   
    .label {
        background: purple;
        width: 100px;
    }
    .value {
        background: red;
        width: 300px;
        position: absolute;
        right: 0;
        bottom: 0;
    }
    

    演示小提琴

注意:前两个选项在 IE < 8 中不起作用(没有一些技巧)

于 2013-09-13T04:53:42.500 回答
0

在此示例中使用此示例 css 多行标签已分配

label {
    display: block;
    margin-left: 20px;
}
input {
    float: left;
    margin-left: -20px;
    margin-right: 7px;
}
于 2013-09-13T04:25:38.050 回答
0

jsfiddle

CSS

.label {
        background: purple;
        float: left;      
        width: 100px;
        display: inline;
        vertical-align: 500px;

}

.value {
        background: red;
        width: 300px;
        float: right;
}
#bor
{
    line-height:40px;
}

HTML

<fieldset>
    <div class="field">
        <div class="label">labl 1:</div>
        <div class="value">Some text</div>
        <br />
        <br />
    </div>

    <div class="field">
        <div class="label">this is a really really long label:</div>
        <div id="bor" class="value">right after":" from previous label</div>
        <br />
    </div>
</fieldset>

在此处输入图像描述

于 2013-09-13T04:36:36.797 回答