I usually set parent's .text-container
display to inline-block to align the width with the child .text
. Here I have an additional problem: parents width is hardcoded as element.style. How do I override the inline style AND adjust to child width at the same time? I can only use CSS.
https://jsfiddle.net/xc7ybt31/
HTML
.text {
display: inline;
}
.text-container {
display: inline-block;
float:left;
}
.main-container {
display: inline-block;
}
<div class="main-container">
<div class="text-container" style="width:100px">
<div class="text">
text
</div>
</div>
</div>