Saturday, 2 August 2014

The Box Model

The box model in CSS describes the boxes which are being generated for HTML-elements. The box model also contains detailed options regarding adjusting margin, border, padding and content for each element. The diagram below shows how the box model is constructed:

The box model in CSS


The illustration above might seem pretty theoretical to look at, so let's try to use the model in an actual case with a headline and some text. The HTML for our example is (from the Universal Declaration of Human Rights):
 
 <h1>Article 1:</h1>

 <p>All human beings are born free
 and equal in dignity and rights.
 They are endowed with reason and conscience
 and should act towards one another in a
 spirit of brotherhood</p>
 
 
By adding some color and font-information the example could be presented as follows:
The example contains two elements: <h1> and <p>. The box model for the two elements can be illustrated as follows:
Even though it may look a bit complicated, the illustration shows how each HTML-element is surrounded by boxes. Boxes which we can adjust using CSS.
The properties which regulate the different boxes are: paddingmargin and border.

Related Posts:

  • JavaScript Popup Boxes JavaScript has three kind of popup boxes: —  Alert box —  Confirm box —  Prompt box. Alert Box: —  An alert box i… Read More
  • Javascript getElementById Method —  The most common way to access an HTML element is to use the id of the element. —  The “innerHTML” property is useful for getting or r… Read More
  • PHP echo —  echo is a language construct, and can be used with or without parentheses: echo or echo(). —  There are some differences between echo… Read More
  • Introduction to PHP PHP (Hypertext Preprocessor): —  PHP is a server scripting language, and is a powerful tool for making dynamic and interactive Web pages quick… Read More
  • PHP Variables —  As with algebra, PHP variables can be used to hold values (x=5) or expressions (z=x+y). —  A variable can have a short name (like x an… Read More