Box Model
Box Model
The box model is a very important concept in CSS because it determines how elements are
positioned within the browser window.
When laying out a document, the browser's rendering engine represents each element as a
rectangular box according to the standard CSS basic box model.
The CSS box model is essentially a box that wraps around every HTML element.
Every box is composed of four areas(or parts), defined by their respective edges:
Content, Padding, Border and Margin.
Content - Contains the "real" content of the element, such as text, an image.
Padding - It is the transparent space between the content of the box and its border.
Border – Even if u cannot see it, every box has a border .This separates the edge of one box from
other surrounding boxes.
Margin – the margin is the distance between the border of a box and the box next to it.
The actual space that an element's box might take on a web page is calculated as:
<html>
<head>
<style>
div {
border: 1px solid black;
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
background-color: orange;
}
</style>
</head>
<body>
<div>This div element has a top margin of 100px, a right margin of 150px, a bottom margin of 100px, and a left margin of
80px.</div>
</body>
</html>
CSS Layout:
CSS page layout techniques allow us to take elements contained in a web page and control where
they're positioned relative to the following factors:
their default position in normal layout flow,
the other elements around them,
their parent container, and
the main viewport/window.
Two such page layout techniques are:
Flexbox
Grid
‘display’ property:
The display property is the most important CSS property for controlling layout.
It specifies if/how an element is displayed.
Every HTML element has a default display value depending on what type of element it is. The default
display value for most elements is block or inline.