Okay, this is a fun challenge! We'll use CSS clip-path for the bottle shape and a clever combination of height and position for the liquid fill. JavaScript will handle updating the fill percentage based on a slider.
Here's the single HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Wine Bottle Fill</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
min-height: 100vh;
background-color: #f0f0f0;
color: #333;
margin: 0;
padding: 20px;
box-sizing: border-box;
}
.bottle-container {
position: relative;
width: 120px; /* Width of the bottle */
height: 350px; /* Height of the bottle */
margin-bottom: 30px;
/* The magic for the bottle shape */
clip-path: polygon(
35% 0%, 65% 0%, /* Top neck */
65% 5%, 80% 15%, /* Right shoulder curve */
80% 85%, /* Right body */
70% 95%, 50% 100%, 30% 95%, /* Bottom curve/punt effect */
20% 85%, /* Left body */
20% 15%, 35% 5% /* Left shoulder curve */
);
background-color: rgba(0, 0, 0, 0.05); /* Slight tint for "glass" */
border: 1px solid rgba(255, 255, 255, 0.2);
box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.3),
0 5px 15px rgba(0, 0, 0, 0.2); /* Outer shadow for depth */
overflow: hidden; /* Crucial: hides the liquid outside the clip-path */
}
.bottle-glass-effect {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to right,
rgba(255, 255, 255, 0.05),
rgba(255, 255, 255, 0.01) 10%,
rgba(0, 0, 0, 0.01) 90%,
rgba(0, 0, 0, 0.05)
);
z-index: 1; /* Above the fill, but below cork/label */
pointer-events: none; /* Allows clicks to pass through to the fill if needed */
}
.bottle-fill {
--fill-percentage: 0%; /* CSS variable to control fill level */
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: var(--fill-percentage); /* Uses the CSS variable */
background-color: #6a0020; /* Deep red wine color */
transition: height 0.5s ease-out; /* Smooth transition for filling */
z-index: 0; /* Below the glass effect */
/* Optional: slight curve for meniscus effect at the top of the liquid */
border-top-left-radius: 5px;
border-top-right-radius: 5px;
}
.bottle-cork {
position: absolute;
top: -15px; /* Position above the bottle */
left: 50%;
transform: translateX(-50%);
width: 30%;
height: 20px;
background-color: #8B4513; /* Cork brown */
border-radius: 50% 50% 0 0; /* Rounded top */
box-shadow: inset 0 -3px 5px rgba(0, 0, 0, 0.3);
z-index: 2; /* On top of everything */
}
.bottle-label {
position: absolute;
top: 40%; /* Position roughly in the middle of the body */
left: 50%;
transform: translate(-50%, -50%);
width: 60%;
height: 25%;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 5px;
display: flex;
justify-content: center;
align-items: center;
font-size: 0.7em;
font-weight: bold;
color: #333;
text-align: center;
line-height: 1.2;
padding: 5px;
box-sizing: border-box;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
z-index: 2; /* On top of everything */
}
.controls {
margin-top: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
input[type="range"] {
width: 250px;
-webkit-appearance: none; /* Remove default styling */
appearance: none;
height: 8px;
background: #ddd;
outline: none;
border-radius: 5px;
opacity: 0.7;
transition: opacity .2s;
cursor: pointer;
}
input[type="range"]:hover {
opacity: 1;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 20px;
height: 20px;
background: #8a012a;
border-radius: 50%;
cursor: grab;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
input[type="range"]::-moz-range-thumb {
width: 20px;
height: 20px;
background: #8a012a;
border-radius: 50%;
cursor: grab;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
label {
margin-bottom: 10px;
font-weight: bold;
font-size: 1.1em;
}
#fillPercentage {
margin-top: 10px;
font-size: 1.2em;
font-weight: bold;
color: #8a012a;
}
</style>
</head>
<body>
<h1>Wine Bottle Fill Level</h1>
<div class="bottle-container">
<div class="bottle-cork"></div>
<div class="bottle-label">
My Fine Wine
<br>
2023 Vintage
</div>
<div class="bottle-fill"></div>
<div class="bottle-glass-effect"></div>
</div>
<div class="controls">
<label for="fillSlider">Adjust Fill Level:</label>
<input type="range" id="fillSlider" min="0" max="100" value="50">
<span id="fillPercentage">50%</span>
</div>
<script>
const fillSlider = document.getElementById('fillSlider');
const bottleFill = document.querySelector('.bottle-fill');
const fillPercentageSpan = document.getElementById('fillPercentage');
function updateFill() {
const percentage = fillSlider.value;
// Set the CSS variable for fill height
bottleFill.style.setProperty('--fill-percentage', percentage + '%');
// Update the displayed percentage
fillPercentageSpan.textContent = percentage + '%';
}
// Add event listener for when the slider value changes
fillSlider.addEventListener('input', updateFill);
// Initial call to set the bottle to the default value (50%) on load
updateFill();
</script>
</body>
</html>