Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Margin to 0 on first and last element in wrapper

  • This topic is empty.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #31984
    steveooo
    Member

    Hi,

    Well, I am looking for a better alternative to this:

    #box>:first-child { margin-top : 0 }
    #box>:last-child { margin-bottom : 0 }

    [#box = wrapper with content]

    #55674
    TheDoc
    Member

    Perhaps you’re looking at it wrong? Seems like you can ignore the content inside the wrapper and just adjust your padding on the wrapper itself.

    #55675
    steveooo
    Member

    Well, the alternative of changing padding of the #box instead of adjusting the elements (in #box) was my first idea. But it doesn’t look very well, if you give #box a background.

    #55676
    TheDoc
    Member

    Perhaps if you showed a link of what you’re trying to accomplish?

    #55677
    steveooo
    Member

    #box is the content wrapper with e.g. a white background whereas the body background is e.g. light blue. So with two different backgrounds you will see the padding of the #box, so your (and my first thought) alternative isn’t suitable for that way.

    I am looking for an alternative where you don’t change the padding (of #box) for replacing the function of

    #box>:first-child { margin-top : 0 }
    #box>:last-child { margin-bottom : 0 }
    #55678
    TheDoc
    Member

    Sorry, I just can’t envision what you’re trying to do. In my head, the padding would work perfectly. If you have a screenshot of what you’d like to do, or a link to it, that’d be great.

    #55679
    steveooo
    Member

    Well, here are two screenshots:

    1. How it should look like:
    http://cl.ly/0H1V2E3v3F3z2v0I2p0i

    2. How it looks without my code (from above):
    http://cl.ly/2l1m1Z0v1i2J3q2w081T

    I think this gives you all informations you need.

    #55680
    TheDoc
    Member

    Why don’t you just do:

    #box h1 { margin-top: 0; }

    #55681
    steveooo
    Member

    Because I want it flexible and the content don’t always start with a headline-tag.

    #55682
    TheDoc
    Member

    Well, content should always start with an h1 tag, but I suppose that’s an argument for another day.

    My suggestion is this: #box h1 { margin-top: 0; }

    If anyone else wants to put their two cents in, by all means.

    #55686
    steveooo
    Member

    Well, my solution is not bad. But I don’t like using the universal selector * ;)

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘CSS’ is closed to new topics and replies.