CSS

Box Model

CSS box model

CSS block box

.classname {
width: 350px;
height: 150px;

padding: 25px;
border: 5px solid black;
margin: 10px;

box-sizing: border-box;
display: inline-block;
}

Declaring the Sides

The thickness of each side can be declared together or separately. Declaring together:


Boxes types


box-sizing: border-box


Margin collapsing

When 2 elements have their margins touch, the margins will combined into one margin value as follow:


margin: auto

Can be used for horizontal centering.


Display types

Block and inline layout makes the normal flow. The default way things on the web behave.

Inner display type and display property

By default, inner boxes within a box are laid out in normal flow. This inner display can be changed by defining display value.

display: inline-block

Inline-block is a very useful display value.


Resources