Grow your CSS skills. Land your dream job.

Target every element inside another element

  • # October 15, 2008 at 8:13 pm

    Hi – have another question.

    Normally, when designers want to set a simple CSS reset, they’d do something like this:

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

    I was wondering if I could do something like this:

    Code:
    #container * { margin:0; padding:0; }

    What I’m trying to do is remove the margin/padding of every element inside a particular div, but not anything else outside of the div.

    Is this possible?

    # October 16, 2008 at 2:25 pm

    Yep pretty sure that will work. Have you tried it?

    # October 16, 2008 at 11:31 pm

    Is that seriously the correct syntax? Damn, I’m good. :D Yes, it worked. Thanks.

    # October 17, 2008 at 1:53 pm

    Good work. I love using it for things like this: #content > *:first-child {margin-top:0;}

    It has many great uses that little asterisk.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".