Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Sure! Let's break down the CSS Box Model properties you mentioned—padding, margin, border, border-radius, and box-shadow—with detailed syntax and examples.


1. CSS Box Model Overview

The Box Model consists of four main parts:

  1. Content – The actual text or elements inside the box.
  2. Padding – Space between the content and the border.
  3. Border – A line surrounding the padding and content.
  4. Margin – Space outside the border, separating the element from others.

Here's a visual representation of the box model:

alt text

2. Padding

  • Padding adds space inside the element, between the content and the border.
  • It can be set individually for top, right, bottom, and left or shorthand for all sides.

Syntax:

padding: 20px; /* Same padding on all sides */
padding: 10px 20px; /* 10px top & bottom, 20px left & right */
padding: 10px 15px 20px 25px; /* Top, Right, Bottom, Left */

3. Margin

  • Margin creates space outside the element, pushing it away from other elements.
  • Works the same way as padding with shorthand and individual values.

Syntax:

margin: 20px; /* Same margin on all sides */
margin: 10px 20px; /* 10px top & bottom, 20px left & right */
margin: 10px 15px 20px 25px; /* Top, Right, Bottom, Left */

4. Border

  • A border surrounds the element and has three properties:
    1. Width (thickness in px, em, rem, etc.)
    2. Style (solid, dashed, dotted, etc.)
    3. Color (any color value)

Syntax:

border: 2px solid black; /* 2px thick, solid black border */
border: 3px dashed red; /* 3px thick, dashed red border */
border: 4px dotted blue; /* 4px thick, dotted blue border */
border: 5px double green; /* 5px thick, double-lined green border */
  • You can also define borders separately:
border-top: 3px solid black;
border-right: 2px dashed red;
border-bottom: 4px dotted blue;
border-left: 5px double green;

5. Border Radius (Rounded Corners)

  • The border-radius property makes corners rounded.
  • It can be applied uniformly or to specific corners.

Syntax:

border-radius: 10px; /* All corners rounded by 10px */
border-radius: 10px 20px; /* Top-left & bottom-right: 10px, Top-right & bottom-left: 20px */
border-radius: 10px 15px 20px 25px; /* TL, TR, BR, BL */
border-radius: 50%; /* Makes a perfect circle if width and height are equal */

6. Box Shadow (Depth Effect)

  • The box-shadow property adds a shadow around the element.
  • It has the following values:
    • Horizontal offset (move shadow left/right)
    • Vertical offset (move shadow up/down)
    • Blur radius (higher value = softer edges)
    • Spread radius (increases shadow size)
    • Color (shadow color)

Syntax:

box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3);
/* 5px right, 5px down, 10px blur, semi-transparent black */

box-shadow: -10px 10px 15px rgba(255, 0, 0, 0.5);
/* 10px left, 10px down, 15px blur, semi-transparent red */

box-shadow: 0px 0px 20px 5px blue;
/* Glowing blue effect */

Example: Applying All These Properties

.card {
  width: 300px;
  height: 200px;
  padding: 20px;
  margin: 30px auto;
  border: 3px solid black;
  border-radius: 15px;
  box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3);
  background-color: white;
}

Result:

  • The card has padding inside to separate content from the border.
  • Margin centers it with spacing.
  • A 3px solid black border surrounds it.
  • 15px border-radius makes the corners rounded.
  • Box-shadow adds depth for a modern look.

Conclusion

  • Padding = Space inside the element.
  • Margin = Space outside the element.
  • Border = The outline of the element.
  • Border-radius = Makes corners rounded.
  • Box-shadow = Adds a shadow effect for depth.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors