-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
CSS Basics
CSS Styling Properties
CSS Box Model
CSS Margin
CSS Padding
CSS Borders
CSS Outline
CSS Height/Width
CSS Max-width
CSS Display
CSS Position
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Box Sizing
CSS Text
CSS Fonts
CSS Icons
CSS Text Effects
CSS Web Fonts
CSS Colors
CSS Backgrounds
CSS Color Keywords
CSS Gradients
CSS Shadows
CSS Links
CSS Lists
CSS Tables
CSS Advanced Selectors & Features
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Attribute Selectors
CSS Specificity
CSS !important
CSS Units
CSS Variables
CSS @property
CSS Math Functions
CSS Media and Image Styling
CSS Image Styling
CSS Image Centering
CSS Image Filters
CSS Image Shapes
CSS object-fit
CSS object-position
CSS Masking
CSS Layout Techniques
CSS Website Layout
CSS Navigation Bar
CSS Dropdowns
CSS Image Gallery
CSS Counters
CSS Pagination
CSS Multiple Columns
CSS User Interface
CSS Flexbox
CSS Grid
CSS Responsive Design (RWD)
CSS Margins are used to create space outside the border of an element.
Margins separate the element from surrounding elements.
You can set margins for:
Top
Right
Bottom
Left
element {
margin: 20px;
}
This sets 20px margin on all four sides.
margin-top: 10px;
margin-right: 15px;
margin-bottom: 20px;
margin-left: 25px;
margin: 10px 15px 20px 25px;
This means:
Top → 10px
Right → 15px
Bottom → 20px
Left → 25px
margin: 10px 15px;
/* Top & Bottom = 10px, Left & Right = 15px */
margin: 10px 15px 20px;
/* Top = 10px, Left & Right = 15px, Bottom = 20px */
div {
width: 300px;
margin: 0 auto;
}
✅ Horizontally centers a block element inside its parent.
Q1. Apply a 30px margin to all sides of a <div>
.
Q2. Set only the top margin of a <p>
to 10px.
Q3. Add 15px margin to the left side of an image.
Q4. Write shorthand margin for: Top = 10px, Right = 20px, Bottom = 30px, Left = 40px.
Q5. Center a block element horizontally using auto
margin.
Q6. Set different margins: 10px top, 5px right, 15px bottom, 0 left.
Q7. Add a 25px bottom margin to all <h2>
headings.
Q8. Write a rule to apply a 20px right margin to elements with class .sidebar
.
Q9. Apply 50px margin only to the left and right of a container.
Q10. Remove all margins from a <body>
tag.
CSS Basics
CSS Styling Properties
CSS Box Model
CSS Margin
CSS Padding
CSS Borders
CSS Outline
CSS Height/Width
CSS Max-width
CSS Display
CSS Position
CSS Z-index
CSS Overflow
CSS Float
CSS Inline-block
CSS Align
CSS Box Sizing
CSS Text
CSS Fonts
CSS Icons
CSS Text Effects
CSS Web Fonts
CSS Colors
CSS Backgrounds
CSS Color Keywords
CSS Gradients
CSS Shadows
CSS Links
CSS Lists
CSS Tables
CSS Advanced Selectors & Features
CSS Combinators
CSS Pseudo-classes
CSS Pseudo-elements
CSS Attribute Selectors
CSS Specificity
CSS !important
CSS Units
CSS Variables
CSS @property
CSS Math Functions
CSS Media and Image Styling
CSS Image Styling
CSS Image Centering
CSS Image Filters
CSS Image Shapes
CSS object-fit
CSS object-position
CSS Masking
CSS Layout Techniques
CSS Website Layout
CSS Navigation Bar
CSS Dropdowns
CSS Image Gallery
CSS Counters
CSS Pagination
CSS Multiple Columns
CSS User Interface
CSS Flexbox
CSS Grid
CSS Responsive Design (RWD)