Hello Dev Community! π
It is officially Day 6 of my web development journey! Yesterday, I learned how to create space using the Box Model. Today, I stepped into the absolute game-changer of frontend layouts: CSS Flexbox.
Before today, aligning elements horizontally or centering a button vertically felt like guesswork. Today, I learned how to control my layout vectors with just a few lines of code.
π§ Key Learnings From Day 6
Flexbox is all about a parent container (the Flex Container) controlling its children (Flex Items) along a main axis and a cross axis.
Here are the structural properties I mastered today:
1. Activating the Layout
By simply applying display: flex; to a parent container, all its direct children instantly align horizontally (row layout) by default. No more messy floats!
2. Controlling Alignment
-
justify-content: Controls spacing along the main axis. I experimented withcenter,space-between(perfect for navbars), andspace-around. -
align-items: Controls spacing along the cross axis. Setting this tocentermakes vertical alignment effortless. -
flex-direction: Allows switching the axis from a row layout to a vertical stack (column), which is crucial for mobile-responsive design.
π οΈ What I Actually Built / Refactored
I took my navigation bar and the "About Me" form from the previous days and completely rebuilt their positioning using Flexbox:
-
The Navbar: Wrapped my logo and nav links in a header container, applied
display: flex;andjustify-content: space-between;. Now the logo sits on the far left and the links sit perfectly on the far right, completely responsive. -
The Centered Button: I finally learned how to perfectly center my submission button inside the form box using
justify-content: center;.
The code looks incredibly clean, and I don't have to use random margins or line breaks (<br>) to push things around anymore!
π― My Goal for Tomorrow (Day 7)
Now that I can create clean structural layouts, it is time to make them look professional on mobile screens:
- Learning Media Queries and Responsive Web Design.
- Understanding how to change layouts smoothly based on different screen sizes.
π¬ Let's Connect!
To the senior devs: What is the one Flexbox shorthand property you use the most? To beginners: Have you cracked the ultimate challenge yetβcentering a <div>?
My Flexbox-powered responsive structures are pushed to GitHub!
[Links in the Comments]
Keep building! π
Top comments (0)