为什么左侧的div
从底部到顶部填充其内容?我知道我可以使用CSS float
属性使两个div顶部对齐。我只是对此片段的哪一部分导致左div
与另一片段的底部对齐感到好奇。
https://codepen.io/anon/pen/YbyePP
.form-row {
display: inline-block;
padding: 0px 30px;
border: 1px red solid;
/*float: left;*/
}
span {
display: block;
}
<div class="form-row">
<span>Soup?</span>
<label><input type="radio" value="Yes">Yes<label><br>
<label><input type="radio" value="No">No<label><br>
</div>
<div class="form-row">
<span>Salad?</span>
<label><input type="radio" value="Yes">Yes<label><br>
<label><input type="radio" value="No">No<label><br>
<label><input type="radio" value="Maybe">Maybe<label><br>
</div>
答案 0 :(得分:6)
vertical-align
元素的默认inline-block
值为baseline
。只需添加vertical-align:top;
。
.form-row {
display: inline-block;
padding: 0px 30px;
border: 1px red solid;
vertical-align:top;
}
span, label {
display: block;
}
<div class="form-row">
<span>Soup?</span>
<label><input type="radio" value="Yes">Yes</label>
<label><input type="radio" value="No">No</label>
</div>
<div class="form-row">
<span>Salad?</span>
<label><input type="radio" value="Yes">Yes</label>
<label><input type="radio" value="No">No</label>
<label><input type="radio" value="Maybe">Maybe</label>
</div>
此外,请确保您正确关闭了标签。此外,如果将label
设置为display:block;
答案 1 :(得分:1)
默认值为基线。尝试vertical-align-top