Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

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 Flexbox for Modern Layouts

- 18.07.26 - ErcanOPAK

📐 Flexbox = Modern Layouts

Floats are dead. Flexbox is modern. Align, distribute, order — all with CSS.

❌ Float Layout

.container {
    overflow: hidden;
}
.item {
    float: left;
    width: 33.33%;
    padding: 10px;
}

✅ Flexbox Layout

.container {
    display: flex;
    flex-wrap: wrap;
}
.item {
    flex: 1 0 33.33%;
    padding: 10px;
}

📝 Flexbox Properties

/* Container Properties */
.container {
    display: flex;
    flex-direction: row | row-reverse | column | column-reverse;
    flex-wrap: wrap | nowrap | wrap-reverse;
    justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly;
    align-items: stretch | flex-start | flex-end | center | baseline;
    align-content: stretch | flex-start | flex-end | center | space-between;
    gap: 10px;
}

/* Item Properties */
.item {
    flex: 0 1 auto;  /* flex-grow flex-shrink flex-basis */
    flex-grow: 1;    /* How much to grow */
    flex-shrink: 0;  /* How much to shrink */
    flex-basis: 200px; /* Initial size */
    align-self: auto | flex-start | flex-end | center | stretch;
    order: 1;        /* Change display order */
}

/* Common Patterns */
/* Navigation */
.nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
}

/* Card Grid */
.card-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
}
.card {
    flex: 1 0 250px;
    padding: 1.5rem;
}

/* Centered Content */
.centered {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

/* Equal Height Cards */
.equal-height {
    display: flex;
    flex-wrap: wrap;
}
.equal-height .card {
    flex: 1;
    min-width: 200px;
}

💡 Flexbox Tips

  • Use flex-wrap for responsive layouts
  • Use gap instead of margin for spacing
  • Use flex: 1 for equal distribution
  • Use order for visual reordering
  • Browser support is excellent

“Flexbox makes layouts easy. Centering, grids, equal heights. Essential for modern design.”

— CSS Developer

Related posts:

CSS: Creating the Ultimate Glassmorphism Look (Modern UI)

CSS: Creating the Ultimate Glassmorphism Look (Modern UI)

CSS: Creating Animated Backgrounds with CSS

CSS: Creating Animated Backgrounds with CSS

CSS: Fix a Flex Item Ignoring max-width Because min-width Defaults to auto and Wins the Comparison

CSS: Fix a Flex Item Ignoring max-width Because min-width Defaults to auto and Wins the Comparison

Views: 7

Post navigation

Windows 11: Use System File Checker to Repair Files
HTML: Use Fieldset and Legend for Form Grouping

Leave a Reply Cancel reply

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

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

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

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (858)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

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