HTML停靠到底部

时间:2012-12-25 02:43:34

标签: html css alignment vertical-alignment dock

我有以下HTML:

<div class="gallery-item">
  <a href="ddd.pdf" style="display:block; width: 100%;">
    <span id="filename_1" style="white-space: nowrap;">Hello</span>
  </a>
  <div id="commands">
    <input type="text" readonly="readonly" value="https://blob">
    <a href="sdfasdfasdfasdf">Delete</a>
  </div>
</div>

CSS:

.gallery-item {
  border: 1px #AAA solid;
  display: inline-block;
  margin: 2px;
  padding 2px;
  width: 130px;
  height: 90px;
  text-align: center;
  border-radius: 5px;
  vertical-align: middle;
}    
  .gallery-item #commands {
    line-height: 4px;
    padding-bottom: 1px;
    vertical-align: bottom;
    bottom: 1px;
  }

我想将commands div与gallery-item分类div的底部对齐。以上都不起作用,commands坚持前面的元素:

enter image description here

1 个答案:

答案 0 :(得分:7)

position: relative添加到父级。

.gallery-item {
    position: relative;
}

.gallery-item #commands {
    position: absolute;
    bottom: 1px;
}

使用position时,需要明确指定。