I'm unable to get a div to fit the size of the text inside of it.
I have 2 divs, and I want the inner div to:
1. Fit inside the outer div.
2. Be centered inside the wrapping div.
The problem I am experiencing is that when I play around with the width of the view, I am getting a large unwanted gap between the text and the div's border, as you can see here:
Can you see the large gap on the right? I want it to be as small as the one on the left side.
How can I prevent this gap, and furthermore, how can I make the div center inside the large div to make its size big enough to fit the text inside of it?
Here is my fiddle test: https://jsfiddle.net/gv1xLd8s
My code:
<div class="wrapper">
<div class="divForText">
Text... Text... Text... Text... Text... Text...
VeryLongWordToCheckTheGapProblemOnLeftAndRightSides
Text... Text...
</div>
</div>
.wrapper{
border: 1px solid blue;
text-align: center;
overflow: hidden;
padding: 25px;
margin: auto;
width: 50%;
}
.divForText{
border: 1px solid black;
display: inline-block;
text-align: left;
padding: 15px;
}
Hope that my question is understood.
Using "word-break: break-all" is not a solution because I don't want to break words in the middle.
I want to accomplish this using pure HTML and CSS, No JavaScript.
Thanks!