You may find it unnecessary, but it is because of an effect that I want to use, and my question is this, if you have how to put a div overlapping another using only relative position in the two
You may find it unnecessary, but it is because of an effect that I want to use, and my question is this, if you have how to put a div overlapping another using only relative position in the two
You can do this:
Using position relative
section div:first-child {
background-color: red;
width: 150px;
height: 150px;
position: relative;
}
section div:last-child {
background-color: blue;
width: 150px;
height: 150px;
position: relative;
margin-top: -130px;
margin-left: 20px;
}
<section>
<div></div>
<div></div>
</section>
Using position relative
and float
section div:first-child {
background-color: red;
width: 150px;
height: 150px;
position: relative;
float: left;
}
section div:last-child {
background-color: blue;
width: 150px;
height: 150px;
position: relative;
top: 20px;
margin-left: 20px;
}
<section>
<div></div>
<div></div>
</section>
Using position absolute
section div:first-child {
background-color: red;
width: 150px;
height: 150px;
position: absolute;
}
section div:last-child {
background-color: blue;
width: 150px;
height: 150px;
position: absolute;
margin-top: 20px;
margin-left: 20px;
}
<section>
<div></div>
<div></div>
</section>
The best way is to use position:absolute;
however, you can set yourself like the following example too
top:-2em; /*Vai subir o elemento 2em em relação ao pai*/
* remembering that you need to put a float
in the element
In this case you will need the div parent and div child.
Follow below:
<div class="x">
<div class="y"></div>
</div>
In css the code looks something like this:
div.x{ position:absolute; }
div.x .y { position:relative; }
Link: