feed RSS Feed RSS


Tag Cloud:
web standards browser Mac internet explorer IE xmas software CSS cascading stylesheet apple xubuntu windows web hosting statistics Santa safari rss reindeers referer php open source linux google funny ftp flash e cards feedburner feed elf ecards e cards cross platform code client christmas articles animated cards


The importance of !important in CSS

CSS and max-widthIn this article I’ll introduce the declaration !important in CSSs and explain how to use it as a “workaround” to avoid adopting IE proprietary code to obtain the max-width effect in your web pages.

When a CSS propriety is specified twice, the browser will commonly use the last one. Let’s see an example:

#main {
width:600px;
width:800px;
}

In this example the browser will assign width 800 pixels to the #main element.

The declaration !important can be used in cascading style sheets to give priority to some parameters.

#main {
width:600px !important;
width:800px;
}

In the example above the browser will give priority to the first declaration and the #main element will be 600 pixels width.

So, what’s the point?
Internet Explorer 6 and previous versions simply ignore the declaration !important (while IE 7 supports them) therefore we can take advance of this issue to design a “browser-based” CSS.

Let’s consider, for example, the CSS proprieties max-width and min-width: these parameters specify a maximum and minimum width of a web element (such as a table or a DIV container). This is a useful feature which allows to create fluid and dynamic layouts that can be displayed correctly both in low resolutions (e.g. 640×480) and in very high resolutions.
Unfortunately IE 6, among other things, doesn’t even support the max/min width declaration: in order to obtain the same effect under IE6 you can use a proprietary code:

#main {
max-width: 900px;
width:expression(document.body.clientWidth > 900? “900px”: “auto” ); /* IE proprietary code */
}

In this example the #main element will be rendered with a maximum width of 900px both in Firefox, Safari, Opera and Internet Explorer.
Please note that the proprietary code width:expression is not a valid CSS declaration, so if you decide to adopt it, your stylesheet won’t respect web standards and won’t be validated.

However, we can use the !important declaration to avoid non-standard CSS expressions. Here is a “workaround” which allows to use max/min width with smart browsers and specify a fixed width for IE 6 users:

#main {
margin: 0 auto 0;
max-width: 900px;
min-width: 770px;
width:auto !important;
width:800px;
}

In the above example (you can see it in action on this website) the declaration !important is used to specify dynamic width attributes to browsers that support them (e.g. Firefox, Netscape, Opera, Safari and IE 7) while the width is fixed to an average value (800 pixels) for IE 6.
This doesn’t solve completely the matter, but can be considered as a workaround to improve your fluid layout appearance avoiding non-standard code.

Posted on: June 5, 2007 - Tags: Web design


Why Internet Explorer is my worst friend

Internet Explorer 6 doesn't support PNG transparencyI haven’t been using Microsoft Windows since 2003; I’m a happy Linux and Mac user.

Why should I talk about Internet Explorer then?

Internet Explorer is the most popular browser among internet surfers; do you have a website? Just check your stats and you’ll find that the average of visitors adopting this browser is around 70-80%.

Visitors don’t use IE because it is a good piece of software; I prefer to think that the majority of non-expert users don’t choose it, they just find the icon on their Windows desktops (I also believe they don’t even choose Windows, as they simply find this OS already installed on their computer… but that’s another story…).

IE users probably won’t experience very serious problems while surfing the net. However, from a web designer perspective, Internet Explorer is a real nightmare: you design and validate your web pages following carefully w3c recommendations in order to have a clean and accessible code… You separate the structure from the graphics using CSS… Then you test your work with different browsers and… boom! You find out that something in IE doesn’t display correctly because it doesn’t support important web standards and CSS specifications.

That’s the paradox: the most wide spread browser in the world doesn’t follow international web standards defined by the World Wide Web Consortium!

Let’s consider two examples with IE version 6 (or lower):

1. A CSS2 declaration called max-width allows to apply a value to the maximum width of a container (e.g. <DIV>) in order to create a fluid layout which resizes and fits lowest monitor resolutions (800×600 is still common, especially in old computers), but don’t exceed in width with higher resolutions. This is an elegant solution to design a dynamic layout, but unfortunately IE 6 doesn’t support it, it just ignores this declaration. These specifications have been written in 1998 by w3c (please check yourself the date at the top of the page), this means that for almost 8 years “developers” at Microsoft simply IGNORED these standards

2. Have you ever heard about PNG image format? It’s really cool as it supports alpha channel transparency, you can obtain very nice effects on your webpages using this format. Internet Explorer doesn’t support it! In the example picture posted here you can see the same web page (containing a simple PNG with alpha channels I created) displayed in IE and in Mozilla Firefox: the first one just shows the PNG image creating a white background, while in Firefox (and other browsers) this PNG blends perfectly with the blue background. Here’s the potential of transparency! It would be great to use PNG on websites to create alpha channel shadows or web elements… But we just can’t… because of Internet Explorer.
(Web designers can adopt GIF format as a kind of replacement for PNG, but that’s not the same. GIF has many limitations as it supports just 1 color transparency and you can’t create antialiased web elements which are independent from background).

Internet Explorer 7 seems to have solved some of these CSS and graphic issues (at least the two ones I mentioned here), clap clap clap ;-) So why I am complaining about it?

Internet Explorer 6 is still the most wide spread browser in the world and version number 7 performs an authenticity control and can be installed just on genuine copies of Microsoft Windows.
We all know there are millions of users out there with a non genuine copy of Windows, aren’t there? (no, I’m not among them, I have a genuine copy: I HAD to buy it because it was included with my laptop…). Although on the net can be easily found procedures which explain how to avoid this control (and install IE7 on a non-genuine copy of windows), I suppose that many users won’t be able to upgrade their software: and that’s the point! (I’m not arguing about the importance of buying original software).

As Internet Explorer plays such an important role on the practical application of web standards, it is Microsoft’s duty to correct these errors and promote the switch to the new version of their browser. If they offer IE 7 as a limited upgrade, I expect many internet surfers will go on using version 6 for some years… [Update 5-10-2007: since october 2007 Internet Explorer 7 is available as a free update also for irregular windows users.]

Alas, what can we do?
It’s simple: do not use Internet Explorer!!!
Unfortunately I’m blowing in the wind: if you are a newbie user or an “average passive windows user” you won’t read this post or similar articles, and even if you came here accidentally, you would get tired and wouldn’t read till here ;-)

As a matter of fact I see you are not reading this page with Internet Explorer and don’t need to be “converted” ;-) Well, spread the word…

Posted on: May 14, 2007 - Tags: Web design


Privacy Policy and Disclaimer - Contacts

Creative Commons By-Nc-NdExcept where otherwise noted, this site and its content are licensed under a Creative Commons Attribution - NonCommercial - NoDerivs License