如何将按钮放在 div 底部和图像下方?

3

所以,这是一个小问题,可能有一个简单的解决方法,但我的大脑显然想不出来。

HTML:

#div {
    position: fixed;
    top: 10%;
    left: 20%;
    right: 20%;
    bottom: 10%;
    z-index: 999;
    text-align: center;
    border-radius: 10px;
}
<div id="div">
  <h1>Settings</h1>
  <center>
    <img src="https://istack.dev59.com/yOhGp.webp" style="width: 30px; margin-bottom: -8px;"><br/>
    <button style="float: bottom; position: absolute; bottom: 10px;">Hide</button>
  </center>
</div>

显然,按钮被卡在了屏幕右侧。但是,我想让它像顶部图片一样处于屏幕中央。谢谢 :)


1
检查我的答案。愉快编程 :) - Rashed Rahat
2个回答

0

移除 button 的样式并添加 margin-top

#div {
  position: fixed;
  top: 10%;
  left: 20%;
  right: 20%;
  bottom: 10%;
  z-index: 999;
  text-align: center;
  border-radius: 10px;
}

#div button {
  margin-top: 30px;
}
<div id="div">
  <h1>Settings</h1>
  <center>
    <img src="https://istack.dev59.com/yOhGp.webp" style="width: 30px; margin-bottom: -8px;"><br/>
    <button>Hide</button>
  </center>
</div>

#div {
    position: fixed;
    top: 10%;
    left: 20%;
    right: 20%;
    bottom: 10%;
    z-index: 999;
    text-align: center;
    border-radius: 10px;
}
<div id="div">
  <h1>Settings</h1>
  <center>
    <img src="https://istack.dev59.com/yOhGp.webp" style="width: 30px; margin-bottom: -8px;"><br/>
    <button style="float: bottom; position: absolute; bottom: 10px;">Hide</button>
  </center>
</div>


0

更新 按钮style style="margin-top: 15px;"

#div {
    position: fixed;
    top: 10%;
    left: 20%;
    right: 20%;
    bottom: 10%;
    z-index: 999;
    text-align: center;
    border-radius: 10px;
}
<div id="div">
  <h1>Settings</h1>
    <img src="https://istack.dev59.com/yOhGp.webp" style="width: 30px; margin-bottom: -8px;"><br/>
    <button style="margin-top: 15px;">Hide</button>
</div>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接