How to resize a css background image in proportion when resizing the browser window?
#main {width:950px; height:100%; background:url(image.jpg) no-repeat center bottom}
When browser resize images should no to go under the text, images should shrink the size to keep the same position and distance
@jitendra; Yes you can use
background-size
property for this but instead ofcover
give value in100%
like thisCSS:
may be that's work for you
read these article for more: http://webdesign.about.com/od/styleproperties/p/blspbgsize.htm , http://robertnyman.com/css3/background-size/background-size.html
This is how i would do it.
http://jsfiddle.net/DpneL/1/
HTML:
CSS:
I'd suggest using this jQuery plugin http://johnpatrickgiven.com/jquery/background-resize/
You can use the css
background-size
. Have a look here: w3c background-sizeYou are probably after
contain
orcover
.Alternatively, here is an example with an img tag: http://jsfiddle.net/jwg2s/ Try resizing your browser.
HTML
CSS
Proportionally it is not going to be right as you are setting a specific width with a percentage height. So try setting a width and height in according percentages.
If you are using height 100% then it's always going to go under your text as well, so that would explain that as it'll go to 100% of the browser.
You may need to experiment with setting width and height as values such as 80% etc. experiment!