Body Element Classes
One thing I’ve started doing somewhat recently is adding a unique class name to the body
element of each page. This allows me to write page-specific CSS as necessary without creating an extra stylesheet. Ideally, there should be styles for common elements that make up the site, rather than style for each page, but this can’t always be avoided. One case could be that a particular page needs to have a slightly different layout than the rest of the site. Body
element class to the rescue!
Internet Explorer 6
We all know Internet Explorer 6 is a regular pain in the neck, right? Fortunately, it’s easy to add IE6-specific style with this selector:
* html [additional selectors...]
For example, the style * html p { font-weight: bold; }
makes all paragraphs bold only in Internet Explorer 6. It’s valid, but no other major browser will apply it. This is useful because sometimes the style needed to make things in IE6 look one way is drastically different than what is needed to make it look the same in all the other browsers. A simpler solution, though, is to tell your client to upgrade his 8-year-old browser. 🙂
“Navbars”
A site typically has a “bar” of navigational links. Vertically laid out navigation is easy to create and append additional links later. Horizontal navigation is sometimes desired instead, but it’s not always as trivial to append and can be a little trickier to achieve.
This tip will be focused on horizontal navigation. First, you should most definitely use unordered lists (the ul
element) to organize your navigation links whether you’re using vertical, horizontal, upside-down, or anything-else-you-can-think of navigation. (See the W3’s excellent webmaster tips for more on unordered lists and their uses.) Once you’ve marked up your navigational links, jump over to the stylesheet and add a display: inline;
line to your navigation’s li
elements. Now take a step back and behold your now-horizontal navigational links!
If you find you need to set the width and height of your links, just set the display type of the a
elements to inline-block
, which I was surprised to find out was actually supported in Internet Explorer 6! Once you’ve set that, your links will behave like block-level elements as far as styling goes, but they will remain positioned inline. Sweet!
Well, that’s all for now. Make sure to check back occasionally for more random web tips from your Uncle Kyle!