An alternative to browsers modern is to set the size of the image being 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 Qualquerum+
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 recur when the width of the element is greater than the same.
However, when applying the property background-size
with the value cover
, we are telling the browser that the image is to occupy the whole dimension of the element.
Potential problem
If the image is not scaled by the element itself, it will be cut by the side that disobeys the scale (see the example on the link above).
If the goal is for the image to be 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 it is applied to.
Example in Jsfiddle
Said: Resize the result window in Jsfiddle to see that the image keeps up with the increase or decrease in the width of the element.
But you want 100% of the original size? or the element it is contained in?
– Israel Zebulon
@Israelzebulon This image is inside a div with width:100%;
– user3081
background-image: url("Hands.jpg"); background-repeat: no-repeat; background-position: block; background-size: 100%;
– user48471