Check out this JSFiddle to see what I have done so far:
html
<div class="results">
<h2>Some data</h2>
<ul style="margin:0;padding:0;">
<li class="resultsListItem" style="list-style-type: none;">
<div class="answerDiv">text</div>
<div class="histogramBar"></div>
<div class="resultDiv"> 7</div>
</li><br>
<li class="resultsListItem" style="list-style-type: none;">
<div class="answerDiv">text</div>
<div class="histogramBar"></div>
<div class="resultDiv"> 1</div>
</li><br>
<li class="resultsListItem" style="list-style-type: none;">
<div class="answerDiv">text</div>
<div class="histogramBar"></div>
<div class="resultDiv"> 4</div>
</li><br>
<li class="resultsListItem" style="list-style-type: none;">
<div class="answerDiv">text</div>
<div class="histogramBar"></div>
<div class="resultDiv"> 4</div>
</li><br>
</ul>
</div>
css
.answerDiv, .resultDiv, .histogramBar {
display: inline-block;
}
.answerDiv, .histogramBar {
float: left;
}
.answerDiv {
margin-right: 10px;
width: 100px;
}
.histogramBar {
height: 6px;
width: 100px;
background-color: #66dd66;
margin-top: 9px;
border-radius: 5px;
transition: width 1s;
}
.histogramBar:hover {
width: 150px;
}
/*text*/
h2 {
font-size: 40px;
color: black;
}
/*alignment*/
.results {
width: 400px;
height: 400px;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
I am facing some challenges in getting all the alignment settings correct. My aim is to have the text inside the .answerDiv's aligned to the left. As the text length increases, it should wrap to a second line if necessary. The histogramBar should also align to the left just next to the text, while the results number should be floated to the right side of the containing div. Additionally, I'm struggling to keep the number on the right fixed when the width of the histogramBar changes.
Unfortunately, I haven't been successful in achieving the desired layout. Since I am relatively new to styling, I acknowledge that my code may not be very elegant.
Can you provide guidance on how I can accomplish this?
Summary - text floats left, histogram bar floats left (just beside text), numbers float right. When hovering over the bar and its width changes, the number on the right should remain unaffected.