Creating a Nike Product Card Using HTML, CSS, and JavaScript #shorts

Posted by


In this tutorial, we will create a Nike product card using HTML, CSS, and JavaScript. This product card will display an image of the Nike product, its name, price, and a "Buy Now" button.

Step 1: Setting up the HTML structure

First, create an HTML file and name it index.html. Inside this file, create the following structure:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Nike Product Card</title>
    <link rel="stylesheet" href="styles.css">
</head>

<body>
    <div class="product-card">
        <img src="nike-shoes.jpg" alt="Nike Shoes">
        <h2>Nike Air Max</h2>
        <p>$150</p>
        <button class="buy-now-btn">Buy Now</button>
    </div>

    <script src="script.js"></script>
</body>

</html>

Step 2: Styling the product card with CSS

Next, create a CSS file and name it styles.css. Inside this file, add the following styles to make the product card look visually appealing:

body {
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}

.product-card {
    border: 1px solid #ccc;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    padding: 20px;
    text-align: center;
}

img {
    width: 100%;
    max-width: 200px;
    border-radius: 5px;
}

h2 {
    margin-top: 10px;
}

p {
    color: #888;
    font-size: 18px;
}

button.buy-now-btn {
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 10px 20px;
    margin-top: 10px;
    cursor: pointer;
}

button.buy-now-btn:hover {
    background-color: #0056b3;
}

Step 3: Adding interactivity with JavaScript

Lastly, create a JavaScript file and name it script.js. Inside this file, add the following code to handle the button click event:

document.querySelector('.buy-now-btn').addEventListener('click', function() {
    alert('Item added to cart!');
});

That’s it! You have now successfully created a Nike product card using HTML, CSS, and JavaScript. Feel free to customize the styles and content of the product card to fit your needs. Happy coding!

0 0 votes
Article Rating
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@codeandcreate
3 months ago