Is there a way to fix this text-wrapping issue?
I have a
.text-wrapper
with a width: fit-content
, but as you can see, there's a LOT of space on the right, is there any way to fix that without having to hard code anything?
Here's a codepen for the demo
https://codepen.io/Lko3001/pen/EaaeXdW
9 Replies
You have 2em of padding on the element along with a max-width. There's not enough width for the padding and the content.
Therefore it breaks onto another line.
Also, don't do this:
There's zero reason to nuke the padding and margin on every element š
If you want the content to dictate the size, git rid of the
max-width
on the .text-wrapper
class.@13eck , the situation is that I want to have a Max with, but by default it should be the size of the content, but I dont want that ugly space on the right, but I understand why it happens, I just dont know how to fix it.
Alos isn't it a good idea to remove padding on everything? So you dont have padding on buttons,body etc. and you have everything "unstyled"?
No you don't want to remove padding on buttons. If you do then there is no, well, padding on the button and it looks bad.
As for the width issue:
* If the value forāhttps://developer.mozilla.org/en-US/docs/Web/CSS/width Sowidth
is less than the value formin-width
, thenmin-width
overrideswidth
. * If the value forwidth
is greater than the value formax-width
, thenmax-width
overrideswidth
.
max-width
is the maximum your width can be, regardless of what you set width
to
And if you want to remove the margin on the body
element then do that. No need to mess up your list items at the same timeI know how it works, what I'm asking is, given a max-width, and also a width of fit-content, can I get rid of that bigger padding on the right
If you want to sure, you just need to add a separate
padding-inline-end
. Though I warn you, having mis-matched padding can look really weirdpadding-inline-end: 0.1em;

I didn't read fully, but did you try
width: max-content
?The problem is that the content + padding is wider than the current max-width
Oh it has the max-width like beck said