css - Why minimizing the window causing the HTML elements to disappear from the parent container itself? -
i have following html code me. have duly tried centrally align parent container div #header
, childs within #header1
, #header2
respectively. when try minimize window parent container seems not centrally aligned , child headers seems collapsed after setting width explicitly width:50%;
of parent container. why so? please explain , me fix this. note horizontal navigation bar below seems associated same bug mentioned above.
<!doctype html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <title></title> <style> *{ margin:0px; padding:0px; } <!--resetter rules browsers--> #bodycontainer { } body { border:black 2px solid; background-color : grey; padding:5px; } #header { margin:10px auto; background-color : red; width:70%; height:80px; -webkit-border-radius:15px; -moz-border-radius:15px; border-radius:15px; } #header1 { display:inline-block; width:50%; text-align:center; line-height:80px; } #header2 { display:inline-block; width:50%; text-align:center; line-height:80px; } #navmenu { list-style-type:none; background-color:#444; border:black 2px solid; text-align:center; margin-bottom:20px; } #content { } #nav { } #navmenu li { border:black 1px solid; background:yellow; border-radius:5px; height:30px; line-height:30px; width:33%; display:inline-block } #navmenu li { text-decoration:none; display:block; } </style> </head> <body> <div id="bodycontainer"> <div id="header"> <div id="header1"><h1>welcome</h1></div><div id="header2"><h1>you choose better !! </h1></div> </div> <div id="content"> <div id="contentheader"> <p>you select ... serve </p> </div> <div id="nav"> <ul id="navmenu"> <li><a href="#">home</a></li><li><a href="#">electronics</a></li><li><a href="#">fashions</a></li> </ul> </div> </div> <div id="sidebar"> </div> <div id="footer"> <p>webapp version numbered v1.0. rights reserved. </p> </div> </div> </body> </html>
the fixed height on #header
prevented text visible on smaller screens there isn't enough space. removed height dynamic.
also added margin left , right of #header1
, #header2
don't stick eachother.
the horizontal menu items collapsing can fixed box-sizing
, , width: 33.33%
more info on box-sizing can found here: http://www.w3schools.com/cssref/css3_pr_box-sizing.asp
hope helped.
Comments
Post a Comment