Margins and block formating contexts (original article from Florent Verschelde)

Test 1 (1 float)

This yellow square is floated left and it has no margin.
This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 100px left margin and a 100px right margin;

This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 100px left margin and a 100px right margin;

Results of test 1:


Test 2 (1 float)

This yellow square is floated left and it has no margin.
This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 200px left margin;

This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 200px left margin;

Results of test 2:


Test 3 (1 float)

This yellow square is a floated left and it has a right margin of 100px.
This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 0px left margin and a 100px right margin;

This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 0px left margin and a 100px right margin;

Results of test 3:


Test 4 (2 floats)

This yellow square is floated left and it has no margin.
This yellow square is a floated right and it has no margin.
This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 100px left margin and a 100px right margin;

This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 100px left margin and a 100px right margin;

Results of test 4:


Test 5 (2 floats)

This yellow square is floated left and it has no margin.
This yellow square is a floated right and it has no margin.
This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 200px right margin;

This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 200px right margin;

Results of test 5:


Test 6 (2 floats)

This yellow square is floated left and it has a right margin of 100px.
This yellow square is floated right and it has a left margin of 100px.
This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 0px left margin and a 0px right margin;

This orange rectangle:
– establishes a new block formating context thanks to the CSS declaration overflow: hidden;
– has a 0px left margin and a 0px right margin;

Results of test 6:


Valid HTML 4.01! CSS compliant