Build a Profile Card Website
Introduction
Hello, developers! I'm excited to share my latest project: a Profile Card. This simple yet elegant project is a great way to showcase your front-end development skills while creating a reusable component for personal or professional use. Whether you're building a personal portfolio or a business website, this Profile Card can add a polished and professional touch to your web pages.
Project Overview
The Profile Card project is a web-based component that displays a user's profile picture, name, status, and a brief description. It's designed to be interactive, allowing users to add or remove friends with just a click of a button. This project demonstrates how to work with dynamic content, event listeners, and conditional rendering using JavaScript.
Features
Interactive Design: Users can interact with the profile card by adding or removing friends.
Responsive Layout: The card is designed to look great on various devices and screen sizes.
Dynamic Content: The profile card dynamically updates its content based on user interactions.
Technologies Used
HTML: Provides the structure for the profile card.
CSS: Styles the card, ensuring it is visually appealing and responsive.
JavaScript: Handles the interactive features, such as updating the card's status and re-rendering content.
Project Structure
Here's an overview of the project structure:
Profile-Card/
├── index.html
├── style.css
└── script.js
index.html: Contains the HTML structure for the Profile Card.
style.css: Includes CSS styles for a clean, modern design.
script.js: Manages the dynamic aspects of the card, such as user interactions and status updates.
Installation
To get started with the project, follow these steps:
Clone the repository:
git clone https://github.com/abhishekgurjar-in/Profile-Card.git
Open the project directory:
cd Profile-Card
Run the project:
- Open the
index.html
file in a web browser to view the Profile Card.
- Open the
Usage
Open the website in a web browser.
View the Profile Card displaying the user's information.
Interact with the card by clicking the "Add Friend" or "Remove Friend" button to update the user's status.
Code Explanation
HTML
The index.html
file defines the structure of the Profile Card, including the header, main content area, and footer. Here’s a snippet:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Profile Card</title>
<link rel="stylesheet" href="style.css" />
<script src="script.js" defer></script>
</head>
<body>
<div class="header">
<h1>Profile Card</h1>
</div>
<div id="main"></div>
<div class="footer">
<p>Made with ❤️ by Abhishek Gurjar</p>
</div>
</body>
</html>
CSS
The style.css
file styles the Profile Card, ensuring it's visually appealing and responsive. Below are some key styles:
body {
width: 100%;
height: 100%;
}
.header {
font-family: sans-serif;
margin: 50px;
text-align: center;
}
#main {
display: flex;
align-items: center;
justify-content: center;
gap: 20px;
width: 100%;
height: 65vh;
}
#card {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
border-radius: 10px;
width: 200px;
height: 300px;
background-color: #ffffff;
}
#card #img {
width: 60px;
height: 60px;
border-radius: 50%;
margin-bottom: 10px;
overflow: hidden;
}
#card button {
padding: 12px 22px;
color: #fff;
border: none;
border-radius: 5px;
}
.footer {
margin: 50px;
text-align: center;
}
JavaScript
The script.js
file contains the logic for dynamically generating the Profile Cards and handling user interactions. Here's a snippet:
var arr = [
{
name: "Alexander",
img: "https://images.unsplash.com/photo-1506794778202-cad84cf45f1d?q=80&w=1887&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
status: "Stranger",
},
{
name: "Alex",
img: "https://images.unsplash.com/photo-1549780101-0c96c7eafbd9?q=80&w=1886&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
status: "Stranger",
},
];
function print() {
var clutter = "";
arr.forEach(function (val, index) {
clutter += `<div id="card">
<div id="img">
<img src="${val.img}">
</div>
<h3>${val.name}</h3>
<h5 id="${val.status}">${val.status}</h5>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Mollitia consequatur nobis natus. Provident?</p>
<button class="${val.status === "Stranger" ? "blue" : "red"}" id="${index}">
${val.status === "Stranger" ? "Add Friend" : "Remove Friend"}
</button>
</div>`;
});
document.querySelector("#main").innerHTML = clutter;
}
print();
document.querySelector("#main").addEventListener("click", function (details) {
arr[details.target.id].status = "Friends";
print();
});
Live Demo
You can check out the live demo of the Profile Card project here.
Conclusion
The Profile Card project was an enjoyable experience, allowing me to practice essential front-end skills such as HTML, CSS, and JavaScript. I hope this project inspires you to create your own interactive components and continue honing your development skills. Happy coding!
Credits
This project was developed as part of my continuous learning journey in front-end development, with a focus on creating interactive and reusable web components.
Author
Abhishek Gurjar
Subscribe to my newsletter
Read articles from Abhishek Gurjar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Abhishek Gurjar
Abhishek Gurjar
I’m Abhishek Gurjar, a Full Stack MERN developer specializing in MongoDB, Express.js, React, and Node.js. I love creating dynamic web apps and sharing insights on web development.