CSS Float and Clear Explained - How does CSS float and clear work?

tobyonline · 175K views · 2013 · 2:50

Open on YouTube

Web developmenttutorial

Why Stack Overflow recommends it

Stack Overflow users link it when a CSS layout question comes down to not understanding how float and clear actually behave.

Recommended by 3 people across 3 different months, 2015 to 2017.

What it is

A short visual tutorial that animates how the CSS float and clear properties affect block elements in a browser window. It shows elements wrapping around floated boxes and how clear moves content below them. Presented by the tobyonline channel.

What people said

Recommends overexchange · 2015-10 · Stack Overflow · on “Why Float is better than position:relative and absolute while we can make layout quickly with position?”

@JitendraVyas Below answers are either theoretical or given examples are wrong, because one has to imagine browser as a 3D container, before understanding `float` property.I think this [this video] is one good explanation on CSS float property. `float:right` works parallel to x-axis in 3d view.

Recommends Kevin · 2016-10 · Stack Overflow · on “Why does the background of a floated element appear to move independent of the content?”

When I started with CSS I was also confused with what float exactly did... You should check out this [this video] video, it really opened my eyes.

Recommends Rahul Das · 2017-07 · Stack Overflow · on “Can't magin-top a div?”

When you assign float:left to an element,the element shifts to that direction and the other elements gets wrapped around it.If you inspect the page, you can see that .side covers the total width of the page and .home is sitting just over it.To make .side align with .home,minimise both the width of .home and the left margin of .side so that both of the div can be accomodated with the width of the page.Next apply float:left to .side, so that it can get aligned with .home . Here's a working solution:- <html> <head> <style> .home { margin-left: 3%; margin-top: 3%; width: 50%; border: 1px solid; float: left; } .side { margin-left:5%; margin-top: 3%; margin-right: 3%; float:left; border: 1px solid

Cites user1063287 · 2016-02 · Stack Overflow · on “Why is a 95% width h1 not as wide as a 95% fixed div?”

Short Version Why is a 95% width h1 not as wide as a 95% fixed div? And what can I do to make the h1 the same width (whilst maintaining the fixed property of the div)? #mobile_wrapper { background: #000; display: block; position: fixed; width: 95%; white-space: nowrap; z-index: 5; box-sizing: border-box; top: 0; left: 0; } #mobile_menu { background: aqua; float: left; display: inline-block; position: static; box-sizing: border-box; width: 60px; } #mobile_logo { background: red; float: left; display: inline-block; position: static; box-sizing: border-box; width: calc(100% - 120px); text-align: center; } #mobile_logo img { max-width: 100%; vertical-align: bottom; } #mobile_cart { width: 60px;