• chabotjeff

    (@chabotjeff)


    here is question for you. why would anyone use the selector “*”? SelectORacle says it “selects any element that is a descendant of a  element.”

    I found a theme with this CSS:

    *
    {
    padding: 0px;
    margin: 0px;

    }

    and it really has made the theme hard to work on!

Viewing 3 replies - 1 through 3 (of 3 total)
  • I have seen this explained as a way of giving complete control to the css author. Browsers handle the “default” display of elements similar but differently. One of the more popular examples is the <ul> element. Try this:

    <ul style="padding:0;">
    <li>asdf</li>
    <li>asdf</li>
    <li>asdf</li>
    <li>asdf</li>
    </ul>

    In Firefox, the list will display with no white space on the left side, but in IE6 the list will display “normally”.

    The absolute reverse is true with the following code:

    <ul style="margin:0;">
    <li>asdf</li>
    <li>asdf</li>
    <li>asdf</li>
    <li>asdf</li>
    </ul>

    Firefox displays normal while IE6 shows no white space on the left.

    While learning css, I can remember reading a few sites that actually suggested using the

    *{
    padding: 0px;
    margin: 0px;
    }

    code at the top of the style sheet to reset the margin and padding of all elements to “0”. This will allow the author to start from scratch defining the values they wanted for all elements.

    I find this to be a very bad practice as it can really bloat the code. I would suggest that this practice not be used, but that is my opinion.

    w3c defines the * selector as the “Universal selector” and states that it will match any element.

    The SelectORade definition is also true because all elements are descendants of <html>.

    Thread Starter chabotjeff

    (@chabotjeff)

    That’s a great explanation. Thanks. I’ve only seen this used once so I assume it is not widely accepted. Hopefully with the new IE we won’t have so many issues with CSS compatibility.

    Thanks for the compliment, glad this helped you to understand this bit of code.

    Hopefully with the new IE we won’t have so many issues with CSS compatibility.

    I really, really, really hope your right. I think the rest of the world does too 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘A whacked out selector – the “*”’ is closed to new replies.