DEV Community

Cover image for Shopping card using the html css and javascript
Prince
Prince

Posted on

Shopping card using the html css and javascript

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=
    , initial-scale=1.0">
    <title>Ecommrce Card</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
    * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
        }
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #f0f2f5;
            height: 100vh;
        }
        .card {
            width: 300px;
            background-color: #fff;
            border-radius: 10px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            overflow: hidden;
            text-align: center;
            padding: 20px;
        }
        .main-image {
            width: 100%;
            height: 250px;
            object-fit: cover;
            border-radius: 10px;
            transition: transform 0.3s ease;
        }
        .thumbnails {
            display: none;
            justify-content: center;
            margin-top: 10px;
        }
        .thumbnail {
            width: 60px;
            height: 60px;
            margin: 0 5px;
            border-radius: 8px;
            cursor: pointer;
            border: 2px solid transparent;
            transition: transform 0.3s, border-color 0.3s;
        }
        .thumbnail:hover,
        .thumbnail.active {
            border-color: #00adb5;
            transform: scale(1.05);
        }
        .details {
            margin-top: 15px;
        }
        .shoe-name {
            font-size: 18px;
            font-weight: bold;
            color: #222;
        }
        .price {
            color: #00adb5;
            font-size: 20px;
            margin-top: 5px;
        }
        .icons {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-top: 15px;
        }
        .icon {
            font-size: 24px;
            color: #888;
            cursor: pointer;
            transition: color 0.3s;
        }
        .icon:hover {
            color: #00adb5;
        }
        .card:hover .thumbnails {
            display: flex;
        }
    </style>
</head>
<body>
    <div class="card">
        <img src="./shoe1.jpeg" id="main-image" 
        class="main-image" alt="Shoe">
        <div class="thumbnails">
            <img src="./shoe1.jpeg" class="thumbnail active"
             data-large="https://via.placeholder.com/300x250?text=Shoe+1" alt="Shoe 1">
            <img src="./shoe2.jpg" class="thumbnail" 
            data-large="https://via.placeholder.com/300x250?text=Shoe+2" alt="Shoe 2">
            <img src="./shoe3.jpeg" class="thumbnail" 
            data-large="https://via.placeholder.com/300x250?text=Shoe+3" alt="Shoe 3">
        </div>
        <div class="details">
            <div class="shoe-name">Premium Shoes</div>
            <div class="price">$59.99</div>
        </div>
        <div class="icons">
            <span class="icon"
             title="Add to Favorites">
             <i class="fas fa-heart"></i></span>
            <span class="icon" title="Add to Cart">
                <i class="fas fa-shopping-cart"></i></span>
        </div>
    </div>
    <script>
        const mainImage = document.getElementById("main-image");
        const thumbnails = document.querySelectorAll(".thumbnail");

        thumbnails.forEach(thumbnail => {
            thumbnail.addEventListener("click", function() {
                // Update main image source
                mainImage.src = this.src;

                // Remove active class from all thumbnails
                thumbnails.forEach(thumb => thumb.classList.remove("active"));

                // Add active class to the clicked thumbnail
                this.classList.add("active");
            });
        });
    </script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
martinso2 profile image
Harry Martin

this is really nice-slick code

Collapse
 
prince_beec5ccde00b7c6c73 profile image
Comment marked as low quality/non-constructive by the community. View Code of Conduct
Prince

thanks follow and share our instagram page for more please instagram.com/webstreet_code/

Collapse
 
link2twenty profile image
Andrew Bone

You can host your code and embed it into a post to be a little more visual give the editor guide a read.

Also on an aside I'd use placehold.co/ for placeholder images as it loads quicker.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.