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.

Flexbox in CSS

Flexbox in CSS

? Flexbox in CSS (Flexible Box Layout)

Flexbox is a powerful CSS layout module designed to arrange items in one dimension — either as a row or a column — and distribute space efficiently between them, even when their size is unknown or dynamic.


Key Concepts

  • Flex container: The parent element with display: flex; or display: inline-flex;

  • Flex items: The direct children inside the flex container.


How to Use Flexbox

1. Create a flex container:

.container {  display: flex; /* or inline-flex */}

2. Main Flexbox Properties

PropertyApplies ToDescriptionExample Values
flex-directionContainerDirection of flex itemsrow (default), column, row-reverse, column-reverse
justify-contentContainerAlign items horizontallyflex-start, center, space-between, space-around, space-evenly, flex-end
align-itemsContainerAlign items vertically (cross axis)stretch (default), center, flex-start, flex-end, baseline
flex-wrapContainerAllow items to wrap onto multiple linesnowrap (default), wrap, wrap-reverse
align-contentContainerAlign wrapped lines verticallyflex-start, center, space-between, space-around, stretch
orderItemChange order of items (default is 0)any integer
flex-growItemHow much an item grows relative to othersnumber (default 0)
flex-shrinkItemHow much an item shrinks relative to othersnumber (default 1)
flex-basisItemInitial size of item before growing/shrinkinglength (px, %), or auto
align-selfItemOverride container's align-items for one itemauto (default), flex-start, center, flex-end, baseline, stretch

Example: Simple Row Layout

.container {  display: flex;  justify-content: space-between;  align-items: center;  height: 100px;  background-color: #eee;}.item {  background-color: #3498db;  color: white;  padding: 20px;  border-radius: 5px;}
<div class="container">  <div class="item">Item 1</div>  <div class="item">Item 2</div>  <div class="item">Item 3</div></div>

Example: Column Layout with Wrapping

.container {  display: flex;  flex-direction: column;  flex-wrap: wrap;  height: 300px;}

Why Use Flexbox?

  • Easy alignment and distribution of space.

  • Works well for dynamic or unknown sizes.

  • Great for responsive layouts.

  • Simple to reorder items visually without changing HTML.


If you want, I can help you build a real example or explain any flexbox property in detail!

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