【发布时间】:2018-11-10 20:43:22
【问题描述】:
【问题讨论】:
-
将两个按钮放在一个 div 中,并给该 div 一个负的 margin-top,例如:margin-top: -15px
【问题讨论】:
使用负边距。假设按钮的高度为 30px:将 -15px 的边距顶部和 -15px 的边距底部应用到按钮容器(例如,如果您希望它位于中间)
body,html{margin: 0; padding: 0;}
.div1 {
background: tomato;
height: 100px;
}
.div2 {
background: grey;
height: 100px;
}
.buttons{
margin-top: -15px;
margin-bottom: -15px;
text-align: center;
}
button {
height: 30px;
}
<div class="div1"></div>
<div class="buttons">
<button>button 1</button>
<button>button 2</button>
</div>
<div class="div2"></div>
【讨论】: