Posted on Monday 18th of December 2006 at 02:37 in Tutorials

IE6 Min/Max-Width hack

This is a nice little "hack" for one of the most annoying oversights in IE6 - minimum/maximum widths.

Say you want to have an image that fills 100% of it's containing area but only up to a maximum of 600px (to stop it from becoming all pixelated and nasty) - typically you would have some CSS looking like:



That would work fine in Firefox/Opera/IE7 but IE6 would just continue scaling the image to 100% of the container forevermore. However, there is a neat little CSS/Javascript trick to emulate this behaviour in IE6.

Using a Javascript expression, you can define a set of implicit sizes for the image based on the width of the browser at that moment in time. See the code below for an example of this application:



The logic for the above code is "if the browser is less than 742 pixels, this value is relevent, if it's more than 1000 pixels, set this value". This means that once the browser is resized above a certain size, the larger value is written in - resulting in a similar effect to the max-width attribute. You could probably put in as many bits of logic as you like into the statement but this is sufficient for those users who wish to have the fudged up browsing experience IE6 gives.

Very useful.

 

Enjoy this article? Why not subscribe to the full RSS feed?

blog comments powered by Disqus
Who is Seopher?

This is me. I'm a 26 year old web developer, blogger and entrepreneur from near London.

I've done work for people like Samsung, Vauxhall, Cadburys, Chevrolet, Center Parcs and TKMaxx.

I've been running this blog since 2006 and have reached more than 1.3 million readers, so feel free to say hi.

Seopher
Subscribe to the RSS Feed

Stay up to date with Seopher.com by subscribing to the RSS feed, either in your browser or subscribe via email using the form below

Updates by Email

By subscribing by email you’re also subscribing to the Seopher.com newsletter; a periodical email outlining new reviews, competitions and other subscriber-only content

  • Top Earning Team
  • dreamhost
  • buy 125x125 advert for $50 pcm
Want to give your product/website exposure?

Paying for a featured review is a great way to give your product, service or website exposure. For as little as $75 you can have a full review on the site forever.

Advertising Bundle! Review + Banner = $100

Buy a review and get a 125x125 advert half price. Your banner gets displayed on over 526 pages for a full month.