html - Image rest of height inside a div-Container -
i have got following code:
html:
<div id="mapwrapper" style="height: 624px;"> <div class="box" id="map"> <h1>campus</h1> <p>description campus map.</p> <img src="abc.png"> </div> </div>
css:
.box { background-color: #fff; border: 1px solid #ccc; border-radius: 5px; padding: 3px; overflow:hidden; height:100%; } #mapwrapper { position: absolute; top: 0px; left: 0px; width: 100%; overflow: hidden; padding: 10px; } #map { display: inline-block; position: relative; } #map img { height: 100%; }
i want image take rest of height, free in map-div. currenty image set 100% , why runs out of box @ bottom. can help? thanks!
why not use display:table
setup, advantage of can add content want first 'row' , image take remaining space (whatever left table height minus first row of content) , scale accordingly.
demo fiddle
html
<div class='table'> <div class='row'> <div class='cell'> <h1>campus</h1> <p>description campus map.</p> </div> </div> <div class='row'> <div class='cell'></div> </div> </div>
css
html, body { height:100%; width:100%; margin:0; padding:0; } .table { display:table; table-layout:fixed; height:624px; width:100%; max-height:624px; } .row { display:table-row; } .cell { display:table-cell; } .row:first-of-type >.cell { height:1%; } .row:last-of-type >.cell { height:100%; background-image:url(http://www.gettyimages.co.uk/cms/staticcontent/1357941082241_new_banner-700x465.jpg); background-size:contain; background-repeat:no-repeat; background-position:center center; }
Comments
Post a Comment