html - CSS position: relative; children do not ignore each other -
i used float. recognized maybe not best way go. trying around position relative. why children of mydiv not ignore each others top ? because not inline-block ?
<div class="mydiv"> <div class="mydiv1"></div> <div class="mydiv2"></div> <div class="mydiv3"></div> <div class="mydiv4"></div> </div> .mydiv { float: left; margin-left: 10px; margin-top: 10px; width: 100px; height: 100px; background-color: grey; } .mydiv1 { background-color: green; width: 10px; height: 10px; position: relative; top: 10px; left: 10px; } .mydiv2 { background-color: red; width: 10px; height: 10px; position: relative; top: 0px; left: 30px; } .mydiv3 { background-color: blue; width: 10px; height: 10px; position: relative; top: 0px; left: 50px; } .mydiv4 { background-color: yellow; width: 10px; height: 10px; position: relative; top: 0px; left: 70px; }
that expected behavior. see mdn documentation
lay out elements though element not positioned, , adjust element's position, without changing layout (and leaving gap element have been had not been positioned).
Comments
Post a Comment