HTML / CSS多个图像重叠

时间:2016-05-25 22:45:22

标签: html css

我想做的是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;
&#13;
&#13;

2 个答案:

答案 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/