Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Position in CSS

Position in CSS

? position in CSS

The position property specifies how an element is positioned in the document. It affects how the element is laid out and how it moves relative to its normal flow, its containing block, or the viewport.


Values

ValueDescription
staticDefault. The element is positioned according to the normal document flow.
relativePositioned relative to its normal position; can be shifted with top, left, etc.
absolutePositioned relative to the nearest positioned ancestor (not static). Removed from normal flow.
fixedPositioned relative to the viewport; stays fixed during scrolling. Removed from normal flow.
stickyActs like relative until a threshold scroll position is reached, then behaves like fixed.

How to Use

.element {  position: relative;  /* or absolute, fixed, sticky */  top: 10px;  left: 20px;}

Detailed Behavior

PositionEffectRemoved from Flow?Reference Point
staticDefault, normal document flowNoN/A
relativeMoves relative to original spot, leaves spaceNoOriginal position
absolutePositioned relative to nearest positioned ancestorYesNearest ancestor with position ? static
fixedStays fixed relative to viewportYesViewport
stickyToggles between relative and fixed based on scrollNo (mostly)Nearest scrollable ancestor or viewport

Example: Relative

.box {  position: relative;  top: 10px;  /* moves down 10px from normal spot */  left: 20px; /* moves right 20px */}

Example: Absolute

.container {  position: relative;}.child {  position: absolute;  top: 0;  right: 0;}

Here .child is positioned at the top-right corner of .container.


Example: Fixed

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

Sticky header stays visible on scroll.


Example: Sticky

.navbar {  position: sticky;  top: 0;  background-color: yellow;}

Navbar sticks to the top when scrolling past it.


Want me to provide interactive examples or explain stacking context with z-index?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql