Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Placing two divs on top of each other without using Position:absolute

Tags:

html

css

I have been trying to add two divs on top of each other without using Position:absolute, and it is not working.

Does anyone know how to do that?? Thank you.

<div class="row" style="background-color:aqua;">
  <div class="col-xs-12 col-sm-12 col-md-12" >   

        <div style="left:0px;">
               <asp:Label ID="lblEmail" runat="server" Text="Label" />
        </div>

        <div style="left:0px;">
             <asp:Button ID="btnJoin" runat="server" Text="a button" 
                  CssClass="btn btn-lg btn-primary"/>
        </div>

  </div>
</div>
like image 380
Taj El Amine Avatar asked Apr 29 '18 04:04

Taj El Amine


People also ask

How do you overlay a div on another div without using position absolute?

By setting this element to grid-column-start to 2, we are assigning this div to one of the same columns as the first element, allowing the overlapping effect to take place without using absolute.

How do I overlay two divs on top of each other?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).

What can I use instead of position absolute?

Fixed. The fixed value is similar to absolute as it can help you position an element anywhere relative to the document, however this value is unaffected by scrolling.

How do I position a div on top of another?

By using a div with style z-index:1; and position: absolute; you can overlay your div on any other div . z-index determines the order in which divs 'stack'. A div with a higher z-index will appear in front of a div with a lower z-index . Note that this property only works with positioned elements.


1 Answers

you can do this using grid.

.parent {
  display: grid;
  grid-template-columns: 1fr;
}

.parent div {
 padding: 50px;
 background-color: rgba(0,0,0,0.5);
 grid-row-start: 1;
 grid-column-start: 1;
}
<div class="parent">
  <div class="child1">
  1
  </div>
  <div class="child2">
  2
  </div>
</div>
like image 61
patelarpan Avatar answered Oct 05 '22 22:10

patelarpan