It’s not that hard doing that with CSS
- 1st, please take a look at the Mozilla Specs for mixed units for
background-size. - 2nd, please consider simply setting
background-size: contain;(IE9+, Safari 4.1+, FF 3.0+, Opera 10+) andmin/max-width/heightfor the container element.