Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
CSS

CSS: Master Position Property for Layout Control

- 11.07.26 - ErcanOPAK

📍 Position = Layout Control

Elements need precise positioning. Position property controls layout. Static, relative, absolute, fixed, sticky.

📝 Position Types

/* Static (default) */
position: static;
- Normal flow
- No positioning

/* Relative */
position: relative;
- Relative to normal position
- Offset with top, right, bottom, left
- Other elements not affected

/* Absolute */
position: absolute;
- Removed from flow
- Relative to nearest positioned ancestor
- Or relative to document

/* Fixed */
position: fixed;
- Removed from flow
- Relative to viewport
- Stays in place on scroll

/* Sticky */
position: sticky;
- Hybrid of relative and fixed
- Sticks when scrolling
- Great for headers

🎯 Practical Examples

/* Modal (fixed) */
.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
}

/* Header (sticky) */
.header {
    position: sticky;
    top: 0;
    background: white;
    z-index: 100;
}

/* Tooltip (absolute) */
.tooltip-container {
    position: relative;
}
.tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
}

/* Overlay (fixed) */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* Dropdown (absolute) */
.dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Sidebar (fixed) */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 250px;
    height: 100%;
    background: #333;
}

/* Centered element (absolute) */
.center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

💡 Position Tips

  • Use relative for positioning context
  • Use absolute for overlays
  • Use fixed for modals and headers
  • Use sticky for section headers
  • Use z-index with positioned elements

“Position property controls layout. Static, relative, absolute, fixed, sticky. Essential for CSS layouts.”

— CSS Developer

Related posts:

CSS: Use clamp() for Responsive Font Sizes Without Media Queries

will-change Can Make Performance Worse

CSS: Solving the Nested Grid Problem with 'subgrid'

Post Views: 2

Post navigation

Windows 11: Use Windows Terminal for Modern CLI
HTML: Use Datalist for Auto-Complete Input

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

July 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Jun    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (597)
  • Add Constraint to SQL Table to ensure email contains @ (582)
  • Average of all values in a column that are not zero in SQL (545)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (512)
  • Find numbers with more than two decimal places in SQL (460)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes
  • Ajax: Use Axios for HTTP Requests
  • JavaScript: Understand Hoisting
  • HTML: Use Web Storage for Client-Side Data
  • CSS: Use Filter Effects for Visual Magic
  • Windows 11: Unlock God Mode for All Settings

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (898)
  • How to make theater mode the default for Youtube (857)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (814)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com