gpt4 book ai didi

HTML/CSS 多张图片重叠

转载 作者:太空宇宙 更新时间:2023-11-04 14:12:51 25 4
gpt4 key购买 nike

我想要制作的是 2 张箭头/指针图像与横幅(另一张图像)重叠。

如何让 2 个箭头保持在图像“上”并将它们对齐到左中和第二个右中?

这是我目前得到的图像: http://prnt.sc/b8govy

我正在使用的代码(上图):

img#art {
display: block;
margin-right: auto;
margin-left: auto;
width: 100%;
height: 100%;
max-height: 300px;
z-index: -1;

}

img#raw {
display: block;
margin-left: auto;
z-index: 2;
}

img#law {
display: block;
margin-right: auto;
z-index: 1;
}
<div id="main">

<img id="raw" src="images/rightarrow.png">
<img id="law" src="images/leftarrow.png">
<img id="art" src="images/banner.png">

</div>

最佳答案

您必须在箭头中使用绝对位置,在父级中使用relative

.banner {
position: relative;
float: left;
}

.arrow {
position: absolute;
z-index: 1;
}

.arrow.left {
top: 50%;
left: 15px;
margin-top: -15px;

width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-right: 15px solid #000;
}

.arrow.right {
top: 50%;
right: 15px;
margin-top: -15px;

width: 0;
height: 0;
border-top: 15px solid transparent;
border-bottom: 15px solid transparent;
border-left: 15px solid #000;
}
<div class="banner">
<div class="arrow left"></div>
<div class="arrow right"></div>

<img src="https://via.placeholder.com/400x200/?text=Banner">
</div>

关于HTML/CSS 多张图片重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37448852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com