Last week I was finishing some code for a webshop. From the admin panel the user can add items with a thumbnail image. These thumbnails have a max-width(100) and max-height(100), because they are shown in a container of 280 x 280 px.
Example:
This is the css for the image:
.prodimg img{
max-height:100px;
max-width:100px;
border:none;
}
This CSS works perfectly on all ‘normal’ browsers. Except…. lte (lower dan or equal to) IE7. In IE the image is viewed in upload size. The max-width and max-height aren’t working correctly.
Put this in your style for IE to solve your max-witdh, max-height problem / bug:
.prodImg img{
width: expression( document.body.clientWidth > 99 ? "100px" : "auto" ); /* sets max-width for IE */
height: expression( this.scrollHeight > 99 ? "100px" : "auto" ); /* sets max-width for IE */
}
Just another IE irriation
If you are using a min-width and min-height like this:
.prodimg img{
min-height:100px;
min-width:100px;
border:none;
}
Use this expression:
.prodimg img{
height: expression( this.scrollHeight < 101 ? "100px" : "auto" ); /* sets min-height for IE */
width: expression( document.body.clientWidth < 101 ? "100px" : "auto" ); /* set min-width for IE */
border:none;
}
Note:
Some images wil look a little unsharp, but the size is correct.
RSS feed for comments on this post. TrackBack URL
December 1st, 2009 at 12:03
Wat nou als de image 300 x 400 is?
Verklein je hem met css waardoor de proporties niet meer correct zijn.
Zelf zal ik in deze situatie kiezen om de image te croppen dmv imageMagick.
Maar daar gaat deze post niet over..
Het is idd vervelend dat min&max-height&width niet werken in de ie browsers ;P
gr Marteb
December 1st, 2009 at 16:42
De img zit zoals je ziet in de css in een container .prodimg. Deze heeft een afmeting van 105 x 105. Als ik de max-height en max-widht dus op 100 zet dan valt de image altijd binnen deze container. Hij houdt dan zijn porporties, want de grootste zijde wordt 100px (max-height of max-width) de andere zijde wordt in dat geval kleiner dan 100px.
Bij jouw voorbeeld van 300(width) x 400(height) krijgt de thumnail dus een formaat van: 75(width) x 100(height). Ik heb de container .prodimg een vast waarde van 105×105 gegeven dus de manier hoe een product getoond wordt verandert dus niet. De thumnail zweeft in de container.
Ik ga zeker even kijken naar je cropper, dit scheelt uiteraard heeeeeel veel opslagruimte! Thanks
December 2nd, 2009 at 15:49
Je hebt gelijk.
Dus alleen als je de width en height afzonderlijk van elkaar aanpast zal dat gebeuren.
Nice!
August 27th, 2010 at 16:39
Super… hier was ik naar op zoek… en het werkt top! Thnx voor deze post.