div's width is 100% so there's lot of extra space left at right. I want div to wrap the text inside it i.e. no extra space should be left in the block. How to achieve it?
<div style="border: 1px solid black;">
Hello there!
</div>
div's width is 100% so there's lot of extra space left at right. I want div to wrap the text inside it i.e. no extra space should be left in the block. How to achieve it?
<div style="border: 1px solid black;">
Hello there!
</div>
Try display: inline-block
:
<div style="border: 1px solid black;display: inline-block">
Hello there!
</div>
<div style="border: 1px solid black;display: inline-block;border: solid">
Hello there!
</div>
You can use display: inline-flex
<div style="border: 1px solid black; display: inline-flex">
Hello there!
</div>
Also if you are not familiar with flex and what it is used for, I recommend having a look at this https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Good reference to understand the power of using flexbox
It seems that you want that complete text of div
should remain inside your div instead of giving scroll
So you can use :
word-wrap: break-word;