How to overlay one div over another div?
How to overlay one div over another div?
597
31-Jul-2023
Updated on 01-Aug-2023
Aryan Kumar
01-Aug-2023To overlay one div over another div, you can use the following CSS properties:
position: This property determines how an element is positioned relative to its parent element. The two most common values for this property areabsoluteandrelative.z-index: This property determines the stacking order of elements. An element with a higher z-index will appear in front of an element with a lower z-index.For example, the following CSS code will overlay a div with the class
overlayover a div with the classcontainer:CSS
The
containerdiv will be positioned relative to its parent element, while theoverlaydiv will be positioned absolutely. This means that theoverlaydiv will be positioned relative to thecontainerdiv, and will appear in front of it.You can also use the
topandleftproperties to position theoverlaydiv relative to thecontainerdiv. For example, the following CSS code will position theoverlaydiv 100px from the top and 100px from the left of thecontainerdiv:CSS