It is time for most sites to drop IE6, especially for projects that are just getting started. If you do make this choice, it is important to realize that there are some new CSS features that you can begin using, and some old habits worth dropping. While there are many sites that describe CSS bugs in IE6, I found no websites that describe working examples to improve your CSS and HTML if you simply drop support for it.
Here are 5 examples from my own project, Haiku Village.
1. Attribute Selectors
You can use attribute selectors for any arbitrary attribute, but I have used it exclusively for form elements.
<style>This will help you delete those arbitrary class names you made up to select certain types of inputs.
input[type="submit"] {
margin-top: 5px;
}
</style>
<input type="submit" value="Save" />
2. Multiple Classes on a Single Element
This is best described with an example:
<style>With IE6, you either needed to make a class name of "icon-delete", or nest one element inside of the other.
.icon {
background: transparent url(/images/icons.png) no-repeat scroll 0 0;
padding: 2px 0 0 20px;
}
.icon.trash {
background-position: 0 -80px;
}
</style>
<span class="icon trash">Delete</span>
3. Sibling Selectors
There are many ways to use sibling selectors. My most recent use of them is to add borders between the list items in a sub menu:
<style>Normally, you would need to introduce a "first" or "last" class name to make the borders only appear between items, and not on the outside.
ul.menu li + li {
border-left: 1px dotted #DADADA;
padding-left: 8px;
}
</style>
3. Child Selectors
If you know that a certain style should only apply immediately within an element, then simply insert a ">" into your stylesheets:
<style>This will ensure that other list items within this list item do not receive the style. It also prevents the necessity to define a new class name, such as "menu-item"
ul.menu > li {
float: left;
margin-right: 7px;
padding: 3px 0 1px;
}
</style>
4. Use :hover on any element
I started web development in 1995, and until recently, I never considered using the :hover meta selector for anything besides the "a" tag. Remove this from your mind, because it is no longer the case. I use :hover to expose some icons when you mouse over a haiku:
<style>Most of us have probably worked around this by either introducing an arbitrary "a" element with an "href='#'", or by adding a class name during a 'mouseover' event.
.haiku .actions {
visibility: hidden;
}
.haiku:hover .actions
:visibility visible
}
</style>
5. New properties available
There are plenty of new properties that you can start using. The most significant are:
- min-width/min-height
- max-width/max-height
- background-attachment - You can use a value of 'fixed'
There are hacks to make all of these work in IE6, but that's the point: You should stop the hacking. Also, did I mention transparent PNGs?
13 comments:
Also the General Sibling Combinator:
h4 ~ p {}
For #2 - Isn't that identical to do this (which already works in IE6):
.icon, .trash {
background-position: 0 -80px;
}
@rmf - thats what I thought, just making sure i'm not going crazy
1,2,3,3,4,5? Surely that's six features? ;)
rmf - No, it's not the same at all. .icon.trash {} refers to an element with more than one class, e.g. class="icon trash".
@thinkdrastic
Ok, but that doesn't really explain the difference. A comma separated list like I have will still apply the styles the same way.
Is it the 'class1.class2' selector only applies styles to elements with both classes? I guess I don't really see the point in that - you should define a 3rd class if that's the case.
@rmf its not a third class, its a way of using the first class and adding an additional class which means not creating a third class.
you can have more than one class on an element is what he is saying
Whilst I support the intent of the article, a couple of items that should be pointed out. I'd love to see IE6 die - that's why I built isie6dead.com - but I also support the efforts of catering for ALL web browsers within reason. There WILL be a time when IE6 can be treated like we treat IE5/5.5, but site visitors will dictate that, not developers.
Just because you choose to support IE6, doesn't mean you can't use CSS items it does not support for other browsers.
There are often other ways of meeting requirements. Ask yourself what you are trying to achieve by using a CSS selector. Is there an alternative? There often is. http://code.google.com/p/ie7-js/ is just one tool that can be used for inject CSS2 features into IE6.
#2 has always worked for me on IE6:
<style>
.foo {color: red;}
.bar {background-color: black;}
</style>
<div class="foo bar">aaaaaaaaaaaaaaaa</div>
#2 works perfectly fine on IE6, up to 3 classes. Then it gets messy.
Oh, and you have two #3 ;-)
Wow, I really do have two #3's. I'm going to leave it that way for everyone's humor.
By the way, the intent of this article was not to convince anyone to stop supporting IE6. I simply wanted developers to start thinking about how they can improve their CSS if their business no longer supports it.
@rmf, @ken, #2
ken, if you'd modify your CSS to:
<style>
.foo {color: red;}
.bar {color: blue;}
.foo.bar { color: green; }
</style>
<div class="foo bar">aaaaaaaaaaaaaaaa</div>
IE6 will display the text in blue and IE7 - green
*All* of these work in IE7? What about IE7 Quirks Mode?
I don't recall IE7 supporting hover on everything except 'a' tags. Etc.
Post a Comment