I have 2 methods for you.
This method resizes the image only visually, not by the actual size in the DOM, but by the visual state after resizing in the middle in the middle of the original size.
HTML:
<img class="fake" src="example.png" />
CSS:
img { -webkit-transform: scale(0.5); -moz-transform: scale(0.5); -ms-transform: scale(0.5); -o-transform: scale(0.5); transform: scale(0.5); filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.9999619230641713, M12=-0.008726535498373935, M21=0.008726535498373935, M22=0.9999619230641713,SizingMethod='auto expand'); }β
Note about browser support : browser statistics are shown as built-in in css .
HTML:
<div id="wrap"> <img class="fake" src="example.png" /> <div id="img_wrap"> <img class="normal" src="example.png" /> </div> </div>β
CSS:
#wrap { overflow: hidden; position: relative; float: left; } #wrap img.fake { float: left; visibility: hidden; width: auto; } #img_wrap { position: absolute; top: 0; right: 0; bottom: 0; left: 0; } #img_wrap img.normal { width: 50%; }β
Note: img.normal and img.fake are the same image.
Note about browser support: this method will work in all browsers, since all browsers support the css properties used in the method.
The method works as follows:
#wrap and #wrap img.fake have a stream#wrap has overflow: hidden so its dimensions are identical to the internal image ( img.fake )img.fake - the only element inside #wrap without absolute positioning, so as not to violate the second step#img_wrap has absolute positioning inside #wrap and extends to the size of the whole element ( #wrap )- The result of the fourth step is that
#img_wrap has the same dimensions as the image. - When setting
width: 50% for img.normal , its size is 50% of #img_wrap and therefore 50% of the original image size.
Vladimir Starkov May 25 '12 at 9:40 2012-05-25 09:40
source share