using flexbox to align elements in a row

flexbox is so good at aligning elements, yes i used to use float left and then percentages and overflow auto or hidden the surrounding div, but now with flex you can just do something like this.

HTML

<div class='flex-row'>
<img src='http://kruxor.com/images/borat_thumbnail.jpg'>
<h2>A Title Tag</h2>
<p>something else</p>
</div>

<div class='flex-row flex-row-reverse'>
<img src='http://kruxor.com/images/borat_thumbnail.jpg'>
<h2>A reversed flex row</h2>
<p>something else</p>
</div>

CSS

.flex-row-reverse {
flex-direction:row-reverse;
}
.flex-row-reverse * {
margin-left:2%;
}
.flex-row {
display:flex;
flex-direction:row;
align-items:center;
}
.flex-row * {
margin-right:2%;
}
.flex-row *:last-child {
margin-right:0%;
}
.flex-row img {
height:64px;
border-radius:5px;
overflow:hidden;
}
.flex-row h2,
.flex-row p
{
justify-content:center;
display: flex;
flex-direction: column;
}

A Title Tag

something else

A reversed flex row

something else

Other Items in css
Page Views

This page has been viewed 324 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

âĪðŸ‘Đ‍ðŸ’ŧðŸ•đ

Random Quote
In this case my anchor this week becomes driving almost 2hrs outside of Atlanta to one of my favorite hard core gyms in the world.. MetroFlex aka The Dungeon. The gym owners turn the heat way up so it becomes a fun sweat box and the gym members just watch from afar and leave me alone. I happily drive myself long distances to find MY ANCHOR. Our anchor allows us to have balance, focus and be as productive as possible. And if you're in the middle of a heavy set and your headphones start to fall off your head, like mine did here.. well.. f*ck the headphones. Let em break and fall. You can always get a new pair, but the iron ain't ever gonna lift itself.
Unknown