Make a div to adjust horizontally to the content

Asked

Viewed 20 times

0

I want to make a DIV fit perfectly to the content inside it.

When typing a text that exceeds the maximum width (max-width) the text breaks and goes down, but the div is not perfectly aligned to the text, it seems that there is a margin to the right.

Using display: inline-block; works until the line needs to be broken due to maximum width.

Follow source code as example: https://codepen.io/Lucas7796/pen/ewejyZ

exemplo

  • To make the text occupy the entire width of the div put text-align:Justify in <p>

  • I had tested this before but I saw that the words were very spaced between them. because it’s not dynamic

  • Face this is the way with the browser renders left-aligned text that is the default, if you do not want that on spaces have to justify the text in the contaier, or else put the exact measure of the container up to where you want to break the line, even if you have more than two lines, this is http://prntscr.com/o9a020

  • Thanks man, my problem is that I have a container that needs to be dynamic because it will receive texts in several languages and depending on the language the text will be larger or smaller, in some cases generating this line break. I will use the strategy of setting the container size according to the language. Thank you!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.