I have a website (g-floors.eu) and I want to make the background (in css I have defined a bg-image for the content) also responsive. Unfortunately I really don\'t have any i
Here is sass mixin for responsive background image that I use. It works for any block
element. Of course the same can work in plain CSS you will just have to calculate padding
manually.
@mixin responsive-bg-image($image-width, $image-height) {
background-size: 100%;
height: 0;
padding-bottom: percentage($image-height / $image-width);
display: block;
}
.my-element {
background: url("images/my-image.png") no-repeat;
// substitute for your image dimensions
@include responsive-bg-image(204, 81);
}
Example http://jsfiddle.net/XbEdW/1/