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.
Linux and Unix watch command tutorial with examples
Tutorial on using watch, a UNIX and Linux command for executing a program periodically and showing a fullscreen output. Examples of watching a file download, a network interface come up, and showing the five most CPU intensive processes.
Build your own Vim statusline
Statuslines in Vim are not hard to create. Making your own means one less dependency in your life.
Custom Vim Bindings in tmux 2.4
tmux 2.4 made a significant change to key bindings. Here is how to support custom keybindings for versions before and after tmux 2.4