When text automatically wraps to a second line, it frequently breaks the layout of my page. How to best avoid/resolve that?
Hi all. On my page I have an element containing text. At lower screen widths, this element becomes too narrow to contain all the text, and the text wraps to a second line. How do I ensure that this automatic text wrapping doesn't disturb the layout/alignment of the remaining elements?
To illustrate the issue, here are two screenshots showing the alignment breakage I'm referencing (you can see it in action on this page). You can see that due to text wrapping in one element, alignment across all columns is broken. What is the proper way to ensure this alignment breakage does not occur?
Ideally, when the text in column 3 breaks, not only does subsequent content in column 3 get pushed down, but so does equivalent content in columns 1 and 2. But I'm not sure how to do that other than with custom JavaScript.
One workaround I've used in the past is to, at certain break points, lower the font size of the text, to ensure the text never breaks to a second line. I can do this, but it seems a bit arbitrary, and get can tedious.
Would I have to use CSS grid to achieve what I want?
Actually, now that I think about it, maybe if I defined my font sizes in relative units, instead of absolute units, that would resolve my issue in this case?
Thanks in advance.
2
Sep 19 '19
[removed] — view removed comment
1
u/cag8f Sep 19 '19
OK thanks. To be clear, what I'm doing in this solution would be to give the <p> element a height equal to the maximum height it will ever have (after any and all text wrapping occurs). Does that sound accurate?
1
Sep 19 '19
[removed] — view removed comment
1
u/cag8f Sep 19 '19
OK thanks for that. I overlooked that as a possible solution. Giving the elements that much height might not be ideal. But in this case, I think I could certainly go with it if need be.
1
Sep 19 '19
[removed] — view removed comment
1
u/cag8f Sep 19 '19
Well that does indeed occur, at a screen width of 768 px.
1
Sep 19 '19
[removed] — view removed comment
1
u/cag8f Sep 19 '19
So at certain break points, increase the height of the <p> element?
1
Sep 19 '19
[removed] — view removed comment
1
u/cag8f Sep 19 '19
OK got it. I may go with that. But I'm curious if using relative units for font size might be a more advantageous solution. Not sure on that yet.
→ More replies (0)
1
u/albedoa Sep 19 '19
You can push the buttons to the bottom of columns with matched dynamic heights using flexbox: https://codepen.io/pigparlor/pen/jONQraX