Forums

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

Home Forums CSS When you float:right everything messes up

  • This topic is empty.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #43114
    apart
    Participant

    Here it [is](http://codepen.io/markomarkogame/pen/ILdth “is”) .

    This day has been a mess and as you can see now this stuff is happening. If you remove **float:right** from **.video** everything is alright, but with it its all .. I don’t know.

    #126787
    Merri
    Participant

    #bodyvideo:after {
    clear: both;
    content: ”;
    display: block;
    }

    :)

    #126791
    apart
    Participant

    This helps but it doesnt tell me what the problems is and how to fix it. Why am I saying this ? Cause I’ve done similar divs and didnt need to do this clear both and display block

    What does this after mean ? .

    Do you know what is problem that is causing this ?

    I just don’t get it, but thanks

    #126793
    Paulie_D
    Member

    I don’t see a problem with the layout in Codepen with float:right applied.

    What is the actual issue?

    #126795
    Merri
    Participant

    The problem is that parent element doesn’t fill up to the height of the floated child elements. Floated elements are taken out of the regular flow of the page.

    The code I provided works as it uses :after to create a pseudo block element that clears the float. It is positioned after the floated elements and because that element is part of the flow the height of the parent element matches the height of the tallest floated element.

    #126797
    Paulie_D
    Member

    Ah yes, I see.


    @markomarkogame
    If you’re going to use floats, you have to know what effect that have on themselves and layout.


    @Merri
    has explained why a clearfix is required.

    https://css-tricks.com/snippets/css/clear-fix/

    #126799
    Merri
    Participant

    Alternative solution instead of the clearfix:

    .video{
    margin-left: 450px;
    width:500px;
    }

    This works, because it adds enough margin to “ignore” the floated element. Also because .video is not floated (and thus stays in page flow) the height of the parent element accounts for it.

    #126801
    apart
    Participant

    Thanks Merri :) Also can i go with overflow:hidden ?

    #126802
    Merri
    Participant

    It also works. It just prevents you from positioning any child elements outside of the parent element’s boundaries which is why clearfix is a “better” solution in some cases.

    In general CSS still lacks a true good layouting solution so we’re very much hacking around positioning elements via floats. Flexbox is the future :)

    #126805
    apart
    Participant

    If we could speed up time … :)

    So i put overflow hidden on videounutra

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