html - 获取按钮悬停在图像上

标签 html twitter-bootstrap css

大家好,我正在尝试让 bootstrap 3 中的按钮与我的图像重叠,我了解 z-index 1 的用法,但我似乎根本无法让它工作。

HTML:

.btn-warning {
  color: #fff;
  background-color: rgba(255, 198, 0, 0.9);
  border: 0;
  padding: 20px;
  border-radius: 26px;
  line-height: 0.428571;
}

.aboutpic {
  margin-bottom: 19px;
}
<div class="aboutpic">
  <img src="//via.placeholder.com/350x150" class="img-responsive">
  <button type="button" class="btn btn-warning">Download CV</button>
</div>

最佳答案

试试这个:

.btn-warning {
 color: #fff;
 background-color: rgba(255,198,0,0.9);
 border: 0;
 padding: 20px;
 border-radius: 26px;
 line-height: 0.428571;
 position: absolute;
 z-index: 1;
 top: 50%; 
 left: 50%; 
 transform: translate(-50%, -50%);
}

您需要向按钮添加一个 position: absolute; 和一个 z-index: 1 以便它可以位于图像的顶部。

codepen.io/lauraeddy/pen/KXEwOW

关于html - 获取按钮悬停在图像上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46840346/

相关文章:

javascript - jQuery在伪之后制作动画

android - 使用 createJS 到 HTML5 以使其在 Android 设备上运行的 Flash 站点覆盖问题

html - 输入量程(设定位置)

html - 在响应框中水平放置表单

javascript - ajax jquery + bootstrap 模式仅在第二次单击时有效

jquery - bxSlider 在 Chrome 中调整大小时未调整大小(响应问题)

javascript - 获取asp :checkbox inside a datalist using jquery的id

html - Bootstrap 等高列中断响应

HTML 不可见组件

css - 如何让图像在多个浏览器中与文本垂直对齐?