Developers everywhere will rejoice as code that appears correctly in every other browser is now likely to display correctly in Internet Explorer 7. IE7 will be a landmark release from Microsoft with a razor sharp rendering engine and standards compliance (well mostly). If you haven’t got it yet the Release Candidate 1 is now out.
But pleasure does not come without pain. Way back in October 2005 Microsoft outlined how existing hacks would break sites in Internet Explorer 7. The following hacks will not work in Internet Explorer 7:
So the choice is now to avoid using these hacks or to deal with them when clients phone up and ask why site layouts are broken. Or perhaps even to code without using hacks at all?
Avoiding hacks is not easy but it isn’t impossible. What’s more you will reap the dividends of passing seamlessly to IE7 once it is released.
Probably one of the most common hacks is the box model hack. This is where IE5 / Windows misinterprets the CSS1 spec by placing borders inside the specified width. Faced with this problem many developers reach for one of the variants on the Box Model Hack. Why not after all - it is quick and easy.
Very often however the Box Model Hack simply isn’t necessary. If you need to apply margins or padding most of the time you can apply it to elements within a div and remain hack free
Look at this XHTML:
<div id="content"> <h3>Title</h3> <p>Paragraph</p> </div>
If the content needs to be given a margin from the edge of the div then many developers will apply margin and padding to the div. This will of course cause problems in IE5/Win so it will be necessary to use a hack.
Providing you don’t have to specify a width, you can avoid hacking by applying the margin and border to the h3 and p tags removing the problem of hacking the div entirely. This is just one example of how hacks are often used without needing them.
Furthermore you can use conditional comments to keep your hacks for IE in one external file. This means you can manage hacks more easily and not serve these stylesheets to browsers that interpret things correctly. The example below serves a stylesheets to IE6 and below but is ignored by non IE browsers:
<!--[if lte IE 6]> <link rel="stylesheet" href="/css/ie6_and_below.css" type="text/css" media="screen" /> <![endif]-->
There is no doubt that at times hacks are unavoidable but with the arrival of IE7 is important to consider how you are using them and to limit their use wherever possible. Otherwise you may well find that your new best friend is your worst enemy.
Have an update or suggestion for this article? You can edit it here and send me a pull request.
Listening to BBC Radio with mpv
The BBC publishes high quality 320 kbps HLS AAC streams that can be used to listen to radio from the command-line using mpv. Here are the URLs and some aliases to start listening quickly.
Vim: So long Pathogen, hello native package loading
Vim 8 added a native way to load third-party packages. This means, for me at least, there is no longer any need to use a third party plugin helper like Pathogen.
Linux and Unix more command tutorial with examples
Tutorial on using more, a UNIX and Linux command for viewing the contents of a file or files one screen at a time. Examples of viewing a file, viewing multiple files, searching using regular expressions and opening the file in a text editor.