我想做的是2个箭头/指针图像与横幅重叠(另一个图像)。
如何让2支箭留在""图像并将它们对齐到中间左边和第二个中间右边?
这是我现在所拥有的形象: http://prnt.sc/b8govy
我使用的代码(对于上图):
<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>
&#13;
{{1}}&#13;
答案 0 :(得分:6)
您必须在箭头中使用position absolute
,在父级中使用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="http://placehold.it/400x200/?text=Banner">
</div>
答案 1 :(得分:1)
display: block; margin-left: auto; margin-right: auto
。position: relative; z-index: -1;
。top: -Xpx;
向上移动。 //或其他单位(vh,rem,em)z-index: 2
float: left
float: right
这里有来自网络随机图片的小提琴 https://jsfiddle.net/warkentien2/xLo1ac5e/