html - Why does this margin flows outsite its parent? -
i have div mainlogo inside div logo. now, when give margin on top, flows outside outer divs. want when give margin-top, should displace downward, instead of flowing margin outside parent.
.header { width: inherit; height: 100px; background-color: #0080ff; box-shadow: 0.5px 0.5px 0.5px 0.5px grey; } .headerdiv img { width: 80px; } .headerdiv { width: 1020px; margin: 0 auto; height: inherit; position: relative; } #mainlogo { height: 80px; width: 350px; margin-top: 10px; }
<div class="header"> <div class="headerdiv"> <a href="onlinequiz login.php"> <div id="mainlogo"> <img src="images/logo.png"></img> </div> </a> </div> </div>
why happen , how can solve it?
tricky margin spec. this page has explanation of behavior running into. if don't want change #mainlogo
whitespace padding
, can work around margin collapse giving overflow: hidden
property .header
.
.header { width: inherit; height: 100px; background-color: #0080ff; box-shadow: 0.5px 0.5px 0.5px 0.5px grey; overflow: hidden; } .headerdiv img { width: 80px; } .headerdiv { width: 1020px; margin: 0 auto; height: inherit; position: relative; } #mainlogo { height: 80px; width: 350px; margin-top: 10px; }
<div class="header"> <div class="headerdiv"> <a href="onlinequiz login.php"> <div id="mainlogo"> <img src="images/logo.png"></img> </div> </a> </div> </div>
also, might consider changing #mainlogo
div
span
, self-closing img
tag avoid unexpected cross-browser quirks.
Comments
Post a Comment