html - 如何在图像向右浮动时使文本重叠
问题描述
我正在尝试在我的网站上创建一个与图像功能重叠的文本。这是我想要的输出:
到目前为止,我已经完成了第一个重叠框。但是,我不能让图像向右浮动,文本向左浮动。
#image-overlap {
position: relative;
margin: 50px 0%;
}
.overlap-text {
position: absolute;
left: 55%;
bottom: 10%;
width: 43%;
font-size: 30px;
line-height: 50px;
font-weight: 200;
color: #000;
}
.overlap-text h1 {
color: #000;
}
#image-overlap-right img {
float: right;
}
.overlap-text-right {
position: absolute;
right: 55%;
bottom: 10%;
width: 43%;
font-size: 30px;
line-height: 50px;
font-weight: 200;
color: #000;
}
.overlap-text-right h1 {
color: #000;
}
.overlap-text-right img {
float: right;
}
<div class="col-md-12">
<div id="image-overlap" class="mt-50">
<img src="https://placehold.it/600x400" alt="" style="max-height: 600px;">
<div class="overlap-text">
<h1> Honest and open bonus structure</h1>
</div>
</div>
<div id="image-overlap-right" class="mt-50">
<img src="https://placehold.it/600x400" alt="" style="max-height: 600px;">
<div class="overlap-text-right">
<h1> Marketing leading infrastructure</h1>
</div>
</div>
</div>
我的问题的codepen是https://codepen.io/mrsalami/pen/MXRZdE
解决方案
那这个呢:
#image-overlap {
position: relative;
margin: 50px 0%;
index:1
}
.overlap-text {
position: absolute;
left: 55%;
bottom: -90%;
width: 43%;
font-size: 30px;
line-height: 50px;
font-weight: 200;
z-index:9;
color: #000;
h1{
color: #000;
}
}
#image-overlap-right{
img{
float:right;
position:relative;
}
}
.overlap-text-right {
position: absolute;
right: 20%;
bottom: 20%;
width: 43%;
font-size: 30px;
line-height: 50px;
font-weight: 200;
color: #000;
h1{
color: #000;
}
img{
float:right;
}
}
<div class="col-md-12">
<div id="image-overlap" class="mt-50">
<img src="https://placehold.it/600x400" alt="" style="max-height: 600px;">
<div class="overlap-text">
<h1> Honest and open bonus structure</h1>
</div>
</div>
<div id="image-overlap-right" class="mt-50">
<img src="https://placehold.it/600x400" alt="" style="max-height: 600px;">
<div class="overlap-text-right">
<h1> Marketing leading infrastructure</h1>
</div>
</div>
</div>
我使用了 z-index 和右/下的组合。无论如何,您必须管理响应部分。所以编辑右/下 %s
推荐阅读
- excel - 用负指数简化方程
- c++ - 从类向量变量中获取值
- java - 在不同场景 javafx 之间共享窗格
- python - python - 如何获取排序数组的索引,但Python中的某些值除外?
- javascript - 从打字稿文件发出导出功能
- python - 当我只有 Kibana 的 URL(没有端口号)时,我可以获得 Kibana 版本吗?
- list - Youtube 空频道列表(https://www.googleapis.com/youtube/v3/channels)中的 categoryId
- javascript - 错误**未捕获的类型错误:从 json 获取数据时无法读取未定义的属性“名词”**
- docker - Kubernetes pods 处于待处理状态
- tcl - TCL 中多个 ::math::linearalgebra::mkMatrices 的容器