JSFiddle - React, Tailwind, and code Playground

by Slava

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS Drag to Scroll</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }

        .scroll-container {
            width: 300px;
            height: 200px;
            overflow: auto;
            overscroll-behavior-x: contain;
            cursor: grab;
            background-color: white;
            border: 1px solid #ccc;
            padding: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        .scroll-container:active {
            cursor: grabbing;
        }

        .scroll-content {
            width: 1000px; /* Wider than the container to enable horizontal scrolling */
            display: flex;
            gap: 20px;
        }

        .scroll-item {
            flex: 0 0 auto;
            width: 150px;
            height: 150px;
            background-color: #3498db;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 24px;
            border-radius: 10px;
        }
    </style>
</head>
<body>
    <div class="scroll-container">
        <div class="scroll-content">
            <div class="scroll-item">1</div>
            <div class="scroll-item">2</div>
            <div class="scroll-item">3</div>
            <div class="scroll-item">4</div>
            <div class="scroll-item">5</div>
        </div>
    </div>
</body>
</html>