BluePink BluePink
XHost
Oferim servicii de instalare, configurare si monitorizare servere linux (router, firewall, dns, web, email, baze de date, aplicatii, server de backup, domain controller, share de retea) de la 50 eur / instalare. Pentru detalii accesati site-ul BluePink.

above banner

banner website
under banner
home html css references contact
HOMEspace above menu HTMLCSSREFERENCES CONTACT
head of content;
monitors
under monitor image space
folder icon space between sign and sugestion Lessons

Box model


An explanation of what the box model is and the way it's treated by completely different user agents.

The term "box model" is usually utilized by individuals once talking regarding CSS-based layouts and style. Not everybody understands what's meant by this although, and not everybody understands why it's therefore necessary.

Any HTML element are often thought-about a box, so the box model applies to all or any HTML (and XHTML) Element.

The box model is that the specification that defines however a box and its attributes relate to every different. In its simplest kind, the box model tells browsers that a box outlined as having breadth one hundred pixels and height fifty pixels ought to be drawn one hundred pixels wide and fifty pixels tall.

There is a lot of you'll be able to augment a box, though, like cushioning, margins, borders, etc. This image ought to facilitate justify what i am close to run through:

Outline of box model

Outline of box model

As you'll be able to see, a box is formed of four distinct elements. the skin one, the margin, is totally invisible. it's no background color, and can not impede parts behind it. The margin is outside the second half, that is that the border. The border outlines the visible portion of the component. within the border is that the third a part of the box, the cushioning, and so within that the content space of the box. The cushioning defines the area between the content space of the box and also the border.
(Note that within the image on top of, the sole border of the 3 drawn that may truly be visible is that the solid line - the dotted lines ar supplementary to assist demonstrate the box model).
When you outline a breadth and a height for your box model CSS, you're process not the complete space preoccupied by the content, padding, border and margin. you're truly simply process the content space itself - the bit right within the middle. The cushioning, border and margin should be supplementary to it so as to calculate the entire area occupied by the box. 
box
The on top of CSS, applied to a box, would mean that that box occupied three hundred pixels of area horizontally on the page. The content of the box would occupy two hundred pixels of that (dashed line supplementary to demonstrate the sting of the world occupied by the box):

Box model demonstration.

Box model demonstration.

In the on top of image, you'll be able to see that the pale blue space is 240 pixels wide (200 pixels of content and twenty pixels cushioning either side). The border is ten pixels wide either aspect, creating the entire breadth together with the border 260 pixels. The margin is twenty pixels either aspect, creating the entire breadth of the box three hundred pixels.
In apply, this will cause some confusion. as an example, if I actually have a one hundred picture element wide area on the market, and wish to fill it with a pale red box with a redness border and alittle quantity of cushioning, it'd be terribly simple to write down the CSS like so:
box
(A declaration of zero, as used for the margin on top of, doesn't need a unit to be supplementary. Any worth aside from zero will need a unit, e.g. commissary for pixels. Also, though "background" is outlined as a shorthand property, it's a lot of wide supported than the a lot of correct "background-color".)
However, that may not provide United States a one hundred picture element wide box, because the breadth declaration defines the content space of the box. The content space of the box are going to be one hundred pixels - the entire breadth of the box as outlined on top of are going to be 122 pixels:
In order to line the on top of box to solely occupy one hundred pixels horizontally, you'd have to be compelled to set the breadth of the content space to be one hundred pixels minus the cushioning and minus the border, during this case seventy eight pixels, like so:

box

To calculate the breadth of a box, together with all cushioning, borders and margins, you'd use the subsequent formula:
total box breadth = content space breadth + left cushioning + right cushioning + left border + right border + left margin + right margin


prev next

Biblography

  1. https://www.addedbytes.com/articles/for-beginners/the-box-model-for-beginners/

Introduction

Syntax and selector

Background

Text style

List

Box model

Floating

Combinators

Pseudo classes

Pseudo element

like hr2
end site bar

Copyright 2014 Florin Bacu | All Rights Reserved

home  contact


under copyright