I sometimes feel like Flex is way too complicated.
Demo: https://jsfiddle.net/304xhguw/
I'm trying to create a container that has multiple lines of text at the end of it:
This should be really easy with Flex, right?
div {
display: flex;
align-items: flex-end;
padding: 20px;
height: 300px;
background: #222;
flex-wrap: wrap;
}
h1 {
width: 100%;
}
h1, p {
color: #fff;
}
Done, the container uses flex, aligns items at the end and h1 creates a new line due to wrap
and width
of 100%
. Perfect.
Not really:
Wait, what did just happen here? <p>
is aligned to the bottom, but <h1>
- not? But the parent container has align-items: flex-end;
, what is this sorcery?
Worry not, there are amazing properties that should work, let's try:
h1 { align-self: flex-end; }
Nothing changes, hm, okay, then maybe:
h1 { align-self: end; }
Okay, what the hell now?
Please, could anyone explain to me what the heck did happen here and why is Flex so stupidly unintuitive? I could have done this using good old position: relative
or even tables
(I know, I know...) in 20 seconds. Is it only me or does Flexbox feel like a great powerful tool that is an overkill and headache for ~95% of the simplest cases?
Note: I DO NOT WANT TO ADD ANY EXTRA DIVS WRAPPERS OR CONTAINERS. I feel like wrapping h1 and p in a div and then aligning it would be fairly easy, but I'm not using Flex in 2021 to add unnecessary markup.