JSFiddle - React, Tailwind, and code Playground
by Nicoledm12
HTML
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Range Slider mit Overlay</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300&display=swap');
* {
margin: 0;
padding: 0;
font-family: "Poppins", sans-serif;
}
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: #151515;
}
.slider-container {
position: relative;
width: 400px;
height: 50px; /* Containerhöhe angepasst für bessere Sichtbarkeit */
}
.range {
width: 100%;
height: 15px;
-webkit-appearance: none;
background: #111;
outline: none;
border-radius: 15px;
box-shadow: inset 0 0 5px rgba(0, 0, 0, 1);
}
.range::-webkit-slider-thumb {
-webkit-appearance: none;
width: 15px;
height: 15px;
border-radius: 50%;
background: #36f9c7;
cursor: pointer;
border: 4px solid #333;
box-shadow: none;
position: relative;
z-index: 2;
transition: width 0.1s, height 0.1s; /* Minimale Vergrößerung */
}
/* Daumen minimal vergrößern, wenn der Benutzer drüber fährt */
.range:hover::-webkit-slider-thumb {
width: 18px;
height: 18px;
margin-top: -2px; /* Minimale Verschiebung */
}
/* Zahl Overlay über dem Daumen */
.thumb-value {
font-weight: 400;
text-align: center;
position: absolute;
top: -25px; /* Position oberhalb des Daumens */
left: 50%; /* Immer in der Mitte */
transform: translateX(-50%); /* Mittig ausrichten */
font-size: 13px;
color: #909090;
background-color: rgba(0, 0, 0, 0.7);
border-radius: 10px;
width: 40px; /* Fixierte Breite der Box */
height: 20px; /* Fixierte Höhe der Box */
display: none; /* Anfangs...