I am using jQuery to insert some divs containing text into my layout. I have styled the divs with display: inline-block
and I want the divs to "shrink-wrap" their content. This seems to be working in most cases but I've come across one case where the text wraps to the next line but the div leaves a bunch of extra padding on the right side. I'm using Chrome Version 53.0.2785.143 m.
Here is a stripped down version of my css and markup. The first box shows what I am describing, the second shows how I expect it to look (which I achieved by explicitly declaring a width). Or you can view it here at jsfiddle: https://jsfiddle.net/3rakaLxc/
[data-station-display] {
border: 1px solid #000000;
width: 490px;
height: 367px;
background-color: #e0e0ee;
}
.stationOverlay {
position: absolute;
left: 0;
top: 0;
}
[data-station-display] .textbox-border {
display: inline-block;
margin: auto;
border-radius: 4px;
padding: 2px;
background: #B7B7B7;
background: linear-gradient(to bottom, #FFFFFF 0%, #808080 100%);
}
[data-station-display] .textbox {
display: inline-block;
max-width: 245px;
padding: 1px;
border-radius: 4px;
font-family: verdana, tahoma, Arial;
font-size: 9.5px;
font-weight: bold;
opacity: 0.6;
cursor: default;
}
<div data-station-display style="position:relative;">
<div class="stationOverlay textbox-border" data-stationid="6" style="top: 337px; left: 0px;">
<div class="textbox yellow" >Station Format: Obstacle Course/Private Lesson</div>
</div>
</div>
<p>
How I think it should look:
</p>
<div data-station-display style="position:relative;">
<div class="stationOverlay textbox-border" data-stationid="6" style="top: 337px; left: 0px;">
<div class="textbox yellow" style="width:218px;">Station Format: Obstacle Course/Private Lesson</div>
</div>
</div>
How can I get rid of the extra space to the right of the word "private"?