Css - Make divs align horizontally
To perfectly arrange your divs horizontally, flexbox is your best friend. Put display: flex;
into the parent container's CSS, and observe the magic.
The parent div becomes a flex container, and all child div
s lineup like well-behaved little ducks in a row.
Harnessing Flexbox powers
Guide the flex children
Flexbox is flexible (pun very much intended) and it gives you the power to precisely position your child divs. Use justify-content: space-evenly;
for magical horizontal alignment:
Making it fit all screens
Now, to ensure your layout does not go haywire across different devices, we use media queries to manage div alignment based on viewport size:
BEM for the win
Why not make your CSS more familiar and intuitive by using BEM notation:
Floats: Outdated and Clunky
If you're dreaming of float
, wake up! It's the age of flexbox and grid. They're sprightly, responsive, and have an insatiable appetite for order:
Be Accessible, Be Liked by Google
Here's a secret - Google digs semantic HTML and a webpage that loads faster than the blink of an eye. So keep your images light and your HTML meaningful.
Time for Testing
Remember, diff'rent strokes for diff'rent folks. Test your layout across several browsers and devices. It's the attention to little details like these that separates the novices from the pros.
Was this article helpful?