An alternative to modern browsers is to set the size of the image that is to be applied as the background of an element by making use of the CSS property background-size
(English) .
Works from the following browser versions:
Safari 3+
Chrome AnyUm +
IE 9+
Opera 10+
Firefox 3.6 +
.minhaClass{
background: url(../imagens/corpo/imagen.jpg) no-repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
Example in JSFiddle
Note that in the image, we are declaring no-repeat
so that it does not repeat itself when the width of the element is greater than it.
However, when we apply the property background-size
to the value cover
, we are telling the browser that the image is to occupy the entire dimension of the element.
Potential problem
If the image is not scaled to the element itself, it will be cut by the side that disobeys the scale (see the example in the link above).
If the goal is that the image be strictly 100% wide and 100% high, then we can use:
.minhaClass{
background: url(../imagens/corpo/imagen.jpg) no-repeat center center;
-webkit-background-size: 100% 100%;
-moz-background-size: 100% 100%;
-o-background-size: 100% 100%;
background-size: 100% 100%;
}
This will force the image to be the same size as the element where it is applied.
Example in JSFiddle
Dita: Resizes the result window in JSFiddle to verify that the image is in tune with increasing or decreasing the width of the element.