【问题标题】:add buttons between and under the mid of two div [closed]在两个 div 的中间和下方添加按钮 [关闭]
【发布时间】:2018-11-10 20:43:22
【问题描述】:

我怎样才能像这样在两个 div 之间添加两个按钮?

【问题讨论】:

  • 将两个按钮放在一个 div 中,并给该 div 一个负的 margin-top,例如:margin-top: -15px

标签: html css button position


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-11-11
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 1970-01-01
    • 2022-06-13
    • 1970-01-01
    • 2021-04-14
    • 1970-01-01
    相关资源
    最近更新 更多