CSS Layout Test Page


Published: 2015-11-30
Updated: 2016-01-03
Web: https://fritzthecat-blog.blogspot.com/2015/11/css-layout-test-page.html


Subject of this article are CSS layout properties, what they cause and how they interact. It is a supplement for my passed Blog about the position property.

You might have noticed that web page layout is not done by assigning something like BorderLayout, GridLayout, FlowLayout, VerticalLayout, TableLayout, ... to some HTML container. Rather you need to set some CSS properties on each element taking part in the layout. These properties are not always that intuitive as expected, especially the position property.


Let's try out by "click and play", not by writing source code.

Below the following 5 setting panels you find 5 HTML <div> elements, visible as coloured bars, spanning the whole width. You can change the CSS layout properties of each of them by using the setting panel of same color.
If you want to reset, press browser Reload, or Shift-Reload in Firefox.
Mind that

Thus these fields are disabled initially.

Text and CSS Settings


Text:
position:
display:
float:
clear:
height:
width:
top:
left:
right:
bottom:
z-index:
Text:
position:
display:
float:
clear:
height:
width:
top:
left:
right:
bottom:
z-index:
Text:
position:
display:
float:
clear:
height:
width:
top:
left:
right:
bottom:
z-index:
Text:
position:
display:
float:
clear:
height:
width:
top:
left:
right:
bottom:
z-index:
Text:
position:
display:
float:
clear:
height:
width:
top:
left:
right:
bottom:
z-index:


Box 1
Box 2
Box 3
Box 4
Box 5

Playground



Here is the playground's HTML:

  <div>
<div id="box-1">Box 1</div>
<div id="box-2">Box 2</div>
<div id="box-3">Box 3</div>
<div id="box-4">Box 4</div>
<div id="box-5">Box 5</div>
</div>

You will find a lot of information and jsfiddle try-out pages on the internet about these CSS properties. Following is a rough description of how they should be understood.

Examples:

Give the yellow box a height of 4 em. Then make it inline. You see that height is ignored now. Then change to inline-block. The height is respected again.

Make box 1 float: left and box 2 float: right. You see that the order of elements is different now, box 3 is between box 1 and box2.

Make box 1 float: left. Then increase its height. You see that it pushes more and more of the other boxes to the right.

Try to arrange all boxes horizontally, by either assigning them all float: left or position: inline-block. Then give them all a width of 15 em. You see that they won't fit into the page and will break into the next layout line.


Feel free to visit my homepage to see the latest state of this page.





ɔ⃝ Fritz Ritzberger, 2015-11-30