Forums

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

Home Forums CSS How do you write CSS for it?

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #44656
    ghafirsayed
    Member

    Hi, whenever I write css for this http://codepen.io/sayed2x2/pen/DaprL, I always think that, there must be a better way of doing it, so I thought lets ask this today on forum.
    1. How do you manage to get rid of the margin of the last element when you have already set the margin of the all divs(inline or something because last-child isn’t supported in all browsers)?
    2.Do you add a clearfix div for each container where items are floating inside because , if I dont, it wouldn’t take the background of the man container and will also have problem setting margins.

    Thanks.

    #134552
    CrocoDillon
    Participant

    Use margin-left and set it to 0 on :first-child.

    #134556
    TheDoc
    Member

    If it’s all on one line, I’ll use the margin-left method as @CrocoDillon mentioned. If things are spread onto multiple lines, I actually just created a codepen for another thread that answer that with a little trick: http://codepen.io/ggilmore/pen/bbd121b060400333d6ce7d886c47bbe6

    #134562
    ghafirsayed
    Member

    Thanks doc , the I didn’t know this overflow:hidden trick, that solves my second problem. But if you give a background color to the wrapper, there still is a 5px margin on the right , how would you remove that? I can do margin-left method, but is there any other way to do it without first-child set to 0?

    #134559
    Paulie_D
    Member

    >I can do margin-left method, but is there any other way to do it without first-child set to 0?

    Yes there are but this one has the best browser support.

    #134567
    ghafirsayed
    Member

    Okay got it thanks a lot.

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