繁体   English   中英

在计算高度的元素内垂直居中放置标签

[英]Center label vertically within element of calculated height

我有以下布局:

<div class="next">
  <div class="main">
    <div class="actions">
      <label><input type="checkbox" checked="">Label1</label>
      <label><input type="checkbox" checked="">Label2</label>
      <button>Button number 1</button>
      <button>Button number 2</button>
    </div>
    <div class="target"></div>
  </div>
</div>

以及相应的样式:

.next {
  position: relative;
  min-height: 320px;
  width: 98vw;
  background: #fee;
}
.main {
  display: inline;
  float: left;
  width: 280px;
    margin: 2px 0 6px 4px;
  background-color: #fff;
}
.target {
    background: #ffa;
    clear: both;
    border: 1px solid black;
  border-radius: 5px;
    width: 280px;
    height: 280px;
    margin: 0 auto;
}
.actions {
    width: 280px;
    margin: 0 auto;
  background: #cfc
}
.actions button {
    width: 67px;
    margin-right: 4px;
    margin-bottom: 4px;
  padding: 2px;
  border-radius: 5px;
}
.actions button:last-child {
    margin-right: 0;
}
.actions button:hover {
  background-color: #eee;
}
.actions button:focus {
  outline: 0;
  background-color: #cce;
}
label {
  font: 10pt sans-serif;
}

如您所见,“操作” div的剩余高度为从整个容器的高度减去“目标”正方形高度后剩下的高度。 现在,我希望“动作” div中的控件垂直对齐。
如果按钮具有短的单行名称,但它们很长并且包裹成两行,它将对齐。 定义行高的常规技巧不起作用。
任何想法如何解决?

http://jsfiddle.net/KgqJS/570/

这样吗? 只需使用显示表(包装器div)+表格单元格(内部div)

.actions {
    display: table;
    ...
}

label {
    display: table-cell;
    vertical-align: middle;
    ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM