【问题标题】:Position button on bottom of screen relative to its image相对于其图像在屏幕底部定位按钮
【发布时间】:2016-07-17 14:36:28
【问题描述】:

我正在努力理解为什么我似乎无法将按钮相对于其图像定位但位于屏幕底部。我已尝试阅读其他问题,但无法从之前的回复中找到解决方案。也许我的情况不同?

基本上,我试图将按钮放置在图像下方,同时保持它(按钮)居中并保持响应。我是第一次提问的长期读者。任何导致解决方案的输入将不胜感激。

也许我的 div 已关闭?

.randomImage {
  position: fixed;
  right: 0;
  left: 0;
  margin-right: auto;
  margin-left: auto;
  height: auto;
  width: auto;
  top: 20%;
}
.btnGroup {
  margin: 0 auto;
  width: 20px;
  color: red;
  position: relative;
}
#buttonOne {
  position: absolute;
}
<div class="blackOverLay">

  <div class="imageContainer">
    <div class="imageHold">
      <image class="randomImage" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQ9dq_0kM7kPFwPJAzHSFNRThXKHmD1ryYDf78YrDNJX7IiExM3sA">
        </img>
        <div class="btnGroup">
          <button id="buttonOne" onclick="closeThis()">CLOSE</button>
        </div>
    </div>
  </div>
</div>

【问题讨论】:

  • &lt;image ...&gt; &lt;/img&gt; 是什么?不是真正有效的 HTML 此外,如果您修复图像容器,您可以将按钮插入固定容器中
  • 谢谢你 mplungjan - 你是对的,不敢相信我写的。固定的。感谢您的反馈!

标签: html css button position


【解决方案1】:

如果我理解你,这就是你想要的。

.randomImage {
position: absolute;

right: 0;
left: 0;
margin-right: auto;
margin-left: auto;

height: auto;
width: auto;
}

.btnGroup {
margin: 0 auto;
width: 20px;
color: red;
}

.imageContainer {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto;
}

#buttonOne {
 position: absolute;
 bottom: 0
 }
<div class="blackOverLay">
    <div class="imageContainer">
        <div class="imageHold">
            <img class="randomImage" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQ9dq_0kM7kPFwPJAzHSFNRThXKHmD1ryYDf78YrDNJX7IiExM3sA" />
            <div class="btnGroup">
                <button id="buttonOne" onclick="closeThis()">CLOSE</button>
            </div>
        </div>
    </div>
</div>

【讨论】:

  • 啊,是的! - 谢谢!我将“底部”设置为 % 以提高响应速度。它似乎在起作用。非常感激。看来我错过了 imageContainer 的 css。 Live'n'learn / 尴尬同时进行。 =D
猜你喜欢
  • 1970-01-01
  • 2013-06-11
  • 2016-06-22
  • 1970-01-01
  • 2018-05-25
  • 1970-01-01
  • 2017-08-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多