Hackforge Academy

Category: javascript

css position

Published on 30 Sep 2026

Explanation

position: absolute removes an element from the normal document flow and positions it relative to a positioned ancestor.

Code:

.container {
  position: relative;
}

.box {
  position: absolute;
  top: 10px;
  right: 10px;
}

Explanation

If no positioned ancestor exists, an absolutely positioned element is generally positioned relative to the initial containing block.

Code:

.box {
  position: absolute;
  top: 0;
  left: 0;
}

Explanation

Absolute positioning is useful for badges, overlays, icons, and elements that need precise placement inside a container.

Code:

.card {
  position: relative;
}

.badge {
  position: absolute;
  top: 5px;
  right: 5px;
}

Explanation

position: fixed positions an element relative to the viewport and keeps it in place while the page scrolls.

Code:

.chat-button {
  position: fixed;
  right: 20px;
  bottom: 20px;
}

Explanation

Fixed positioning is commonly used for floating action buttons, chat buttons, and fixed navigation elements.

Code:

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

πŸš€ 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