To create a visual representation of a percentage range, you can overlay two images - one showing an empty bottle and the other filled. Here is a simple example to achieve this:
Using JavaScript:
let from = document.querySelector('#from'),
to = document.querySelector('#to'),
filling = document.querySelector('.filling');
[from, to].forEach(input =>{
input.addEventListener('keyup', () => {
filling.style.top = from.value + '%';
filling.style.height = (to.value - from.value) + '%';
});
});
.bottle {
position: relative;
width: 50px;
height: 125px;
border: 1px solid #ccc;
background: #fefefe;
}
.filling {
position: absolute;
width: 100%;
background: blue;
top: 15%;
height: 50%;
}
from: <input id="from" value="15" />% - to: <input id="to" value="75" />
<br /><br />
<div class="bottle">
<div class="filling"></div>
</div>
Alternatively, instead of calculating the filling, you can calculate the empty parts for a different approach. Here's another example:
let emptyTop = document.querySelector('.top'),
emptyBottom = document.querySelector('.bottom');
document.querySelector('#from').addEventListener('keyup', e => {
emptyTop.style.height = e.target.value + '%';
});
document.querySelector('#to').addEventListener('keyup', e => {
emptyBottom.style.height = (100 - e.target.value) + '%';
});
.bottle {
position: relative;
width: 50px;
height: 125px;
border: 1px solid #ccc;
background: blue;
}
.top, .bottom {
position: absolute;
width: 100%;
background: #fff;
}
.top {
top: 0;
height: 15%;
}
.bottom {
bottom: 0;
height: 25%;
}
from: <input id="from" value="15" />% - to: <input id="to" value="75" />
<br /><br />
<div class="bottle">
<div class="top"></div>
<div class="bottom"></div>
</div>