css - 当英雄图像有文本时定位响应式英雄按钮
问题描述
我习惯于创建一个英雄图像作为背景图像,并在顶部覆盖一个英雄按钮作为相对/内嵌组件。
今天,我收到了一张带有文字的英雄图片(见下文)。英雄按钮应该位于“检查开放注册概述...”的文本下方。但是,发生了两件事: 1. 当我像往常一样定位按钮时,当我缩小屏幕长度时,按钮不会停留在该文本下方。2. 按钮不会出现在主图上方,而是位于图像底部下方,不会出现在顶部。
<!-- Hero Image-->
<div id="banner" class="row">
<div class="col-xs-12">
<img src="../img/headers/bannerHome_OpenEnrollment.png" class="img-responsive" alt="open enrollment" tabindex="0">
<!-- Hero Button -->
<div class="hero-text">
<button class="btn btn-secondary hero-text">Learn More <img src="../img/icons/btnArrow_white.png"></button>
</div>
</div>
</div>
#banner .col-xs-12 {
padding-left: 0;
padding-right: 0;
background-color: #49c8f4;
position: relative;
}
.img-responsive {
margin-left: auto;
margin-right: auto;
display: block;
}
.hero-text button {
border: none;
position: absolute;
margin-left: 150px;
margin-bottom: 150px;
outline: 0;
display: inline-block;
color: white;
background-color: #003057;
font-size: 24px;
font-family: "Klinic Slab Medium";
cursor:pointer;
}
解决方案
将文本烘焙到图像中并不是最佳实践。您最好在 html 中构建文本部分。这将允许它们相对于彼此定位。
推荐阅读
- python - 将 Series 中的每个值替换为其相对排名
- python - 将 PDF 报告排序到正确的目录“TypeError:预期的 str、字节或 os.PathLike 对象,而不是列表”
- angular - 部署到heroku时,简单的角度服务没有上下文(this = undefined)?
- c - Gtk3 - 如何在我的 GtkApplication 中通过 GAction 收听加速器?
- swift - 如何用数据数组填充 UICollectionView?
- excel - 从源文件夹到目标文件夹的文件夹列表复制vba
- python - 使用while循环更新多个函数中使用的分配变量 - PYTHON
- java - 如何在 Spring 中将 @Repository 添加到非控制器类?
- python - 将 CSV 从 AWS S3 实例导入到 Numpy
- javascript - 如何使用 JS 根据不同的屏幕尺寸加载不同的 HTML 内容