Resize block after text wrap

I want to create pricing list like on image. I use flex container on each line, inside are two text blocks and hr between them.
.option {
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 1ch;
}

.option hr {
flex: 1 1 auto;
}
.option {
display: flex;
justify-content: space-between;
align-items: flex-end;
gap: 1ch;
}

.option hr {
flex: 1 1 auto;
}
If name text is too long, it takes whole space and wraps to next line. Problem: its block keeps whole width, which makes hr disappear. Alternatively I tried
.option hr {
flex: 1 1 100%;
}
.option hr {
flex: 1 1 100%;
}
which makes hr take all available space, but forcefully wraps name to longest word. And making
.option .name {
flex: 1 0 auto;
}
.option .name {
flex: 1 0 auto;
}
prevents name from ever wrapping when needed. How can I solve it? Flexbox is not required if there are other ways to do it. Main condition is to take full width, stretch hr, keep small space between text and hr, align all items at bottom when wrapping
No description
14 Replies
Arctomachine
ArctomachineOP3w ago
Better picture of final result
Arctomachine
ArctomachineOP3w ago
No description
dys 🐙
dys 🐙3w ago
You could put a <div> in the middle with a flex-grow to fill the space and a border-bottom of dotted?
clevermissfox
clevermissfox3w ago
Turn flex grow off on the word you want to be it's intrinsic size. Flex: 1 0 auto turns off flex shrink so it won't shrink eg won't wrap
Arctomachine
ArctomachineOP3w ago
There already is hr for that But I still need to wrap when it is too long to fit into one line
clevermissfox
clevermissfox3w ago
Yes that’s why you need flex shrink on . You turned flex shrink of with flex: 1 0 auto Just comment out the flex declaration or set it to revert and see if that’s the behaviour you’re looking for
Arctomachine
ArctomachineOP3w ago
Tried 0 1 auto and tried revert, they both give same result as initial problem has
clevermissfox
clevermissfox3w ago
Can you make a codepen please
Arctomachine
ArctomachineOP3w ago
https://codepen.io/Arctomachine/pen/dPbLjMB here. Resize it until text wraps, line disappears after that No idea why it centers line vertically, but it is not important here.
clevermissfox
clevermissfox3w ago
Try to give the hr a flex-shrink 0 I’m on mobile but will look at this on desktop in a few hours if no one else has popped in first You may want to approach this with grid tbh Could also give the hr a min width:3ch; and nuke the margin so it aligns to the bottom.
Arctomachine
ArctomachineOP3w ago
Shrink 0 same result
Arctomachine
ArctomachineOP3w ago
Dynamic flex base? Looks cool. Still leaves some gaps when text wraps by half, but that should work
clevermissfox
clevermissfox3w ago
That's because if you out bgs on e rrythibg the box thst holds the text is taking up thst space, it's not an upside down L where the hr can impeded into that space , it would have to be pulled out of the flow to overlap unto the text box space Upside down ELLLL. HR starts here Not Upside down ELLL. HR cannot impede

Did you find this page helpful?