html - 如何在 div 底部和图像下方放置一个按钮?

标签 html css

所以,这是一个小问题,可能有一个我的大脑显然无法想出的小解决方案。

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="/image/yOhGp.png" style="width: 30px; margin-bottom: -8px;"><br/>
    <button style="float: bottom; position: absolute; bottom: 10px;">Hide</button>
  </center>
</div>

显然,按钮卡在了屏幕的右侧。但是,我希望它像顶部的图像一样位于中间。谢谢:)

最佳答案

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="/image/yOhGp.png" 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="/image/yOhGp.png" style="width: 30px; margin-bottom: -8px;"><br/>
    <button style="float: bottom; position: absolute; bottom: 10px;">Hide</button>
  </center>
</div>

关于html - 如何在 div 底部和图像下方放置一个按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67000902/

相关文章:

css - html中的Source sans pro字体

jquery - 如何在使用 jQuery 隐藏输入字段后正确定位 HTML5 表单验证错误消息?

html - Html 中的视频添加与 Github 不同步

javascript - Ajax调用相同的id

php - 找不到图像时的图像高度和宽度

html - 叠加层上的 CSS 文本

javascript - ajax 自动完成文本框搜索箭头键选择不起作用

javascript - 为什么 jquery .text() 总是返回一个空字符串?

html - 为什么 img 可点击空间包含整个 div?

html - 设置可滚动的背景图像