In some scenarios, you may need a child element to appear below (or behind) its parent, regardless of their position in the DOM tree. However, setting z-index and position: relative doesn't seem to achieve this effect.
Thanks to advancements in CSS, you can now accomplish this using CSS 3D transforms. Here's how:
background: red;<br> width: 100px;<br> height: 100px;<br> transform-style: preserve-3d;<br> position: relative;<br>}</p><p>.child {<br> background: blue;<br> width: 100px;<br> height: 100px;<br> position: absolute;<br> top: -5px;<br> left: -5px;<br> transform: translateZ(-10px)<br>}
Parent<br> <div><div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">Child
In this example:
As a result, the child element will appear behind the parent, overlaying it without obscuring its view. This technique works in all modern browsers.
The above is the detailed content of How to Place a Child Element Behind Its Parent Without Using Z-index?. For more information, please follow other related articles on the PHP Chinese website!