Model & Layouts

Date : 02 Jun 2025
Author : You
Tags :

The CSS Box Model Explained (With Examples)

The CSS Box Model is a fundamental concept that describes how elements are structured and spaced in a webpage. Every HTML element is represented as a rectangular box with the following layers:

Box Model Components

Example

.box {
  width: 200px;
  padding: 20px;
  border: 5px solid black;
  margin: 10px;
}

Mastering CSS Floats and Positioning

CSS provides different ways to control the placement of elements on a page.

Floats

The float property allows elements to be positioned to the left or right, making text wrap around them.

.image {
  float: left;
  margin-right: 10px;
}

Positioning

The position property helps define an element’s placement:

Example:

.fixed-header {
  position: fixed;
  top: 0;
  width: 100%;
}

The Difference Between Inline, Block, and Inline-Block Elements

Elements in CSS are displayed in different ways:

Block Elements

div {
  display: block;
}

Inline Elements

span {
  display: inline;
}

Inline-Block Elements

.inline-box {
  display: inline-block;
  width: 100px;
  height: 50px;
}

Conclusion

Understanding the CSS Box Model and layout techniques is essential for creating well-structured web pages. Mastering positioning, floats, and display properties will help you design flexible and visually appealing layouts.

Table of Contents