简体   繁体   中英

How to place div inside a div over another div?

I have a div, which has an image inside another div. I would like to place the inner div over the second div. So the arrow in the image below should go over the red. Is this possible?

在此处输入图像描述

 .puscicaAnimacija { bottom: -2%; height: 5%; margin-bottom: -10px; z-index: 2; position: absolute; }
 <div class="first"> <div style="display: flex; justify-content: center;"> <img src="https://via.placeholder.com/100" class="puscicaAnimacija" /> </div> </div> <div class="second"> </div>

You should put position:relative on the second div that refers to the .puscicaAnimacija class, then using the property z-index on the second element with an higher value than in the first.

.puscicaAnimacija{
   position: relative;
}

.second{
   position: absolute;
   z-index: 3;
}

In order to use z-index the parent element must be positioned. Use position:relative on the div you want to go under.

Note: I've converted a few of your classNames to use named classes as well as added some additional CSS for demonstration purposes

Perhaps try something like this:

.first {
  background: navy;
  width: 300px;
  height: 100px;
  position: relative;
}

.ontop {
  background: whitesmoke;
  width: 300px;
  height: 50px;
  position: absolute;
  bottom: 0;
}

.second {
  background: red;
  width: 300px;
  height: 50px;
}

.puscicaAnimacija {
  bottom: -40%;
  left: 10%;
  height: 48px;
  position: absolute;
}
<div class="first">
  <div class="ontop">
    <img src="https://cdn-icons-png.flaticon.com/512/159/159119.png" class="puscicaAnimacija" />
  </div>
</div>

<div class="second">
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM