html - Parent div with a background-image "collapses" when adding a child div -


i attempting create game first thing user sees start-menu modal on top of game background.

basic html:

<div class="game-board">     <div class="menu"> </div> </div> 

css:

html, body{     min-height:100%; }   .game-board{     background-image: url(../images/sand.png);     width: 1260px;     height: 100%; }  .menu{   position: absolute;   width: 400px;   right: 0;   top: 30%;   left: 31%;   background: whitesmoke;   border-radius: 4px; } 

i expected above code show background-image in background, , somewhere near middle of image, "modal" above background. however, reason i'd love know, parent div .game-board collapsed no height , no background image, modal appears fine. why this?

rule - height in percentage work in css, parent element should have height can calculated.

for example, when .game-board should have height of 100% - question arises 100% of what? because parent element body in case, not have height specified explicitly. min-height not work because not fix height of element particular value on particular view port. example, if viewport has height 100px min-height: 100% mean 100px infinity. height rule on .game-board doesn't work.

to fix this, change min-height height

html, body {     height: 100%; } 

also, absolutely positioned menu, needs have height if there no content of yet inside it, else not appear.

here working fiddle. http://jsfiddle.net/8dhfac8w/


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -