Home > Article > Web Front-end > Shopping card using the html css and javascript
<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> <div class="card"> <img src="./shoe1.jpeg" id="main-image" class="main-image" alt="Shopping card using the html css and javascript"> <div class="thumbnails"> <img src="./shoe1.jpeg" class="thumbnail active" data-large="https://via.placeholder.com/300x250?text=Shopping card using the html css and javascript+1" alt="Shopping card using the html css and javascript 1"> <img src="./shoe2.jpg" class="thumbnail" data-large="https://via.placeholder.com/300x250?text=Shopping card using the html css and javascript+2" alt="Shopping card using the html css and javascript 2"> <img src="./shoe3.jpeg" class="thumbnail" data-large="https://via.placeholder.com/300x250?text=Shopping card using the html css and javascript+3" alt="Shopping card using the html css and javascript 3"> </div> <div class="details"> <div class="shoe-name">Premium Shopping card using the html css and javascripts</div> <div class="price">.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>
The above is the detailed content of Shopping card using the html css and javascript. For more information, please follow other related articles on the PHP Chinese website!