-
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)
position
Property in CSS?The position
property in CSS specifies how an element is positioned in the document flow.
It works in combination with the properties:top
, right
, bottom
, and left
.
Value | Description |
---|---|
static |
Default. Elements are positioned in the normal document flow. |
relative |
Positioned relative to its normal position. |
absolute |
Positioned relative to the nearest positioned ancestor. |
fixed |
Positioned relative to the viewport. Stays in place even on scroll. |
sticky |
Toggles between relative and fixed , based on scroll position. |
element {
position: relative;
top: 10px;
left: 20px;
}
static
div {
position: static; /* default */
}
✅ Cannot use top/right/bottom/left.
relative
div {
position: relative;
top: 10px;
}
✅ Moves the element relative to its original place.
absolute
div {
position: absolute;
top: 0;
right: 0;
}
✅ Positioned relative to the closest ancestor with a position other than static.
fixed
div {
position: fixed;
bottom: 0;
right: 0;
}
✅ Stays fixed in viewport, even on scroll.
sticky
div {
position: sticky;
top: 0;
}
✅ Sticks to the top of the page while scrolling, then behaves like relative
.
Q1. Make a <div>
fixed to the top-right corner of the viewport.
Q2. Position a paragraph 20px down from its normal spot using relative
.
Q3. Place a box absolutely inside a positioned parent element.
Q4. Create a sticky header that sticks to the top on scroll.
Q5. Write a class .fixed-footer
that pins an element to the bottom of the screen.
Q6. Move a button 30px to the left and 10px up using position: relative
.
Q7. Set a child element to absolute
and position it 10px from all sides of its parent.
Q8. Use position: static
and explain why top
doesn’t work.
Q9. Make a notification box that stays visible at top right during scroll using fixed
.
Q10. Set a container with position: relative
and an icon inside as absolute
.
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)