When applying a negative margin to an element why the text 1 over the background of child 2 and behind the text , i thought it will be behind the whole box.
html {
font-size: 40px;
font-weight: bold;
}
.child1 {
color: white;
background-color: red;
}
.child2 {
color: black;
background-color: green;
margin: -35px 0 0 20px;
}
<body>
<div>
<div class="child1">text 1 some text here</div>
<div class="child2">text 2 other text here</div>
</div>
</body>
2
Answers
You can simply make the whole .child2 box move over the .child1 elt using css
z-index
property:Full example: