Html 在计算高度的元素内垂直居中标签
我的布局如下:Html 在计算高度的元素内垂直居中标签,html,css,Html,Css,我的布局如下: <div class="next"> <div class="main"> <div class="actions"> <label><input type="checkbox" checked="">Label1</label> <label><input type="checkbox" checked="">Label2</label>
<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>
如您所见,“actions”div的剩余高度是从整个容器的高度减去“target”平方高度后剩下的高度。现在,我希望“actions”div中的控件垂直对齐。如果按钮的名称是短的一行名称,则控件会对齐,但它们很长,并且会换行成两行。通常用于定义线高度的技巧不起作用。
有没有办法解决这个问题 类似的东西?只需使用显示表(包装器div)+表单元格(内部div)
不确定这是否是您想要的,但尝试添加
display:inline块;垂直对齐:中间对齐代码>标签和按钮。@Rachel Gallen是的,谢谢@婆罗门·戴夫:诀窍是将v-align设置为标签和按钮,谢谢你们,我想接受你们的一个答案
.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;
}
.actions {
display: table;
...
}
label {
display: table-cell;
vertical-align: middle;
...
}