html - Resizing divs and background images to fit page with CSS -


say want have couple of divs on page images in background (like this: http://www.ubudhanginggardens.com/). know how set size of divs, problem background image stays same if make web browser smaller... want background image scale up/down web browser.

css

body, html {     height: 100%;     width: 100%;     margin: 0px; } #container1 {     float: left;     height: 100%;     width: 50%;     background-image: url(../img/1.png); } #container2 {     float: left;     height: 100%;     width: 50%;     background-image: url(../img/2.png); } 

this can done pure css , not require media queries.

to make images flexible, add max-width:100% , height:auto. image max-width:100% , height:auto works in ie7, not in ie8 (yes, weird ie bug). fix this, need add width:auto\9 ie8.

source

css:

img {     max-width: 100%;     height: auto;     width: auto\9; /* ie8 */ } 

and if want enforce fixed max width of image, place inside container, example:

<div style="max-width:500px;">     <img src="..." /> </div> 

jsfiddle example here. no javascript required. works in latest versions of chrome, firefox , ie (which i've tested).


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -