Hackforge Academy

Category: html_css

css position

Published on 29 Jun 2026

Explanation

The position property controls how an element is placed within a webpage. Common values are static, relative, absolute, fixed, and sticky.

Code:

.box {
  position: relative;
}

Explanation

Relative positioning moves an element from its normal position while keeping its original space in the layout.

Code:

.box {
  position: relative;
  top: 20px;
  left: 30px;
}

Explanation

Absolute positioning places an element relative to its nearest positioned ancestor.

Code:

.box {
  position: absolute;
  top: 50px;
  right: 20px;
}

Explanation

Fixed positioning keeps an element in the same location even when the page is scrolled.

Code:

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

Explanation

Sticky positioning behaves like relative positioning until a specified scroll position is reached, after which it sticks in place.

Code:

.menu {
  position: sticky;
  top: 0;
}

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community