Grow your CSS skills. Land your dream job.

Clearing Divs Question

  • # May 21, 2013 at 10:07 pm

    I know a bit about clear divs but just have a couple of questions.

    Sometimes in my html I put in between the last div and start of a new div I create a div class of clear.

    is it best to create a class for clear on html or just add it to parent class css example .nav

    # May 22, 2013 at 12:43 am

    I think you’ll find most people prefer to use the *clearfix* method: http://nicolasgallagher.com/micro-clearfix-hack/

    # May 22, 2013 at 12:43 am

    @mwbcomputers I’ve been using this as of recent:

    element:after {
    content: "";
    display: table;
    clear: both;
    }

    I got the idea from Chris Coyier’s article here.

    Personally, i wouldn’t add extra markup to clear a float just use pseudos like :after.

    # May 22, 2013 at 12:59 am

    Thanks will watch some videos on you tube about. its juts I am creating a eight column footer 4 on top and 4 below. I have heard about clear fix but never understood it. will give it ago.

    # May 22, 2013 at 8:06 am

    You can target a specific child element such as the following, This will target only the fifth column and clear the float left, This is being really specific and avoids uneccassry classes, ids or other tags.

    **HTML**









    **CSS**

    footer .column:nth-child(5) {
    clear: left;
    }

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

You must be logged in to reply to this topic.

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