首先,我使用的是Mac上的Google Chrome 34。
这是HTML,一切看起来都很正确:
你可以在http://codepen.io/caio/pen/yFzvK上看到这些代码的实际效果。
神秘之处在于项目1和2(使用
此外,带有
你能帮我理解为什么会发生这种情况吗?以及如何解决它?
这是HTML,一切看起来都很正确:
<div class="toolbar">
<button type="button" class="item">Item 1</button>
<button type="button" class="item">Item 2</button>
<div class="item">Item 3</div>
<div class="item">Item 4</div>
</div>
这是我的CSS(好吧,它是SCSS):
.toolbar {
border: 1px solid #000;
border-width: 1px 0;
display: table;
width: 100%;
.item {
background: transparent;
border: 1px solid #000;
border-width: 0 1px 0 0;
display: table-cell;
height: 40px; /* <---------- */
outline: none;
vertical-align: center;
white-space: nowrap;
&:last-child { border-right: 0; }
}
}
你可以在http://codepen.io/caio/pen/yFzvK上看到这些代码的实际效果。
神秘之处在于项目1和2(使用
button
标签)假定正确的高度( 40px
),但是项目3和4(使用 div
标签)假定更大的高度( 50px
)。此外,带有
div
标签的元素神秘地右对齐。你能帮我理解为什么会发生这种情况吗?以及如何解决它?