Jan 8
2007

What is so !important?

I came across a problem when working with ordered and unordered lists.
Here is an ordered list in case you were wondering what the hell it is:

  1. Proper mark-up
  2. I didn’t type these numbers
  3. Each item gets a number
  4. Or maybe a roman numeral

I want to give all my normal-looking regular lists a little style. No problem, I add a 50px left margin to the li’s. My paragraphs have a 30px margin and I like the lists to be indented a little bit. Just like the example above.

But what about my other lists? Like a list of links that I want to display inline? Whoa - they can’t have a 50px left margin! That would look like crap! So, I gave these lists a special class (named “links” or whatever). I styled them inline with NO margin.

Well, since the style properties cascade, I figured a margin of zero would bring the link lists back to normal. Well, crap! It didn’t work! How about making a negative margin (-50px)? Nope. That didn’t work either. Why not? I don’t know.

Then I remembered the “!important” declaration. I haven’t used it, but I notice it when I look at other websites’ CSS. Yes, we all do it. I found a reference to this declaration in my trusty CSS Pocket Reference (by Eric Meyer) which says “those rules marked !important are given greater weight than those that are not.”

Simple enough. So I tried it:

ol.links li
{display: inline;
margin: 0 !important;}

And it worked like a charm. I love web design.

One Comment!

  1. 1
    Carol

    my hands smell like oranges…even after I washed them! Sweet.

Leave a Comment:

Fields marked with asterisks(*) are required but I won't publish, share, or sell this info. Put any name in the name field if you want to remain anonymous (you sly fox).

« Home Page

Note: This post is over a year and a half old. You may want to check later in this blog to see if there is new information relevant to your comment.


Close
E-mail It