CSS 多行标签对齐

标签 css

如何将 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;

}

非常感谢:)

最佳答案

这里有一些选项供您选择:

  1. 使用display:inline-block:

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

    Demo fiddle

  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;
    }
    

    Demo fiddle

  3. 使用position:absolute

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

    Demo fiddle

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

关于CSS 多行标签对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18778259/

相关文章:

html - 模态的CSS - 如何将它定位在页面上方但在窗口中可滚动

html - CSS 关键帧动画在 Safari 上不流畅,但在 Chrome 上有效

javascript - 右侧的 float 组件指示页面中的部分

css - 如何使用css垂直对齐混合元素?

html - mediawiki 中的嵌套编号列表

html - CSS object fit image 展开布局

javascript - 当 ng-show 值等于 false 时的 AngularJs 动画

css - JqueryUi 自动完成组合框按钮

html - 为什么对多个元素使用 Class 而对一个元素使用 ID?

javascript - IE10 中的高度 100% 问题。在 IE 和所有其他浏览器中以 Quirks 模式工作