首页 > 解决方案 > 在两个 div 的中间和中间添加按钮

问题描述

我怎么能像这样在两个 div 之间添加两个按钮? 在此处输入图像描述

标签: htmlcssbuttonposition

解决方案


使用负边距。假设按钮的高度为 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>


推荐阅读