Introduction
Card components are very common in modern user interface designs and they are visible everywhere. It is a versatile and indispensable tool for presenting information and content in an engaging and visually appealing manner. In this article, we get familiar with card components and learn how we can build good-looking card components by building a profile card component.
Final Result
- This is how It looks in the end If you want to try it. You can get the starter file and final code in this
Final Code and Starter File
Code and Starter file: GitHub Repo
Live Site: Site Link
Creating Profile Card Component
What are profile cards?
Profile cards are UI components used to display information about an individual in a concise and visually appealing manner. Generally, a profile card includes a profile picture, a name, job title, location, contact information, and skills. There may also be a brief bio. Keeping all this in mind we will build our profile card.
Let's start building
The first step, let's create an html document containing above mentioned details
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="./assets/images/favicon.ico"/>
<link rel="stylesheet" href="./style/style.css">
<title>profile-card</title>
</head>
<body>
<main class="profile-card">
<img class="profile-pic" src="./assets/images/profile-pic.png">
<div class="details">
<h1 class="name">
Whiskers Whiskerton
</h1>
<div class="location"><img src="./assets/images/location-dot-solid.svg"/><span >NEW YORK</span></div>
<p class="description">
UI/UX designer and front-end developer
</p>
<div class="button">
<button class="message-button">Message</button>
<button class="follow-button following">Follow</button>
</div>
<div class="skills">
<h2>SKILLS</h2>
<ul class="skills-list">
<li>UI/UX</li>
<li>Front End Development</li>
<li>HTML</li>
<li>CSS</li>
<li>Javascript</li>
<li>React</li>
<li>Bootstap</li>
</ul>
</div>
</div>
</main>
</body>
</html>
<main>
contains all the details and this will be our card.I have already added css file in
<head>
.I have also defined class name for styling.
Now we deal with styling which is the most important part of this
- Removing default styles:
/* GLOBAL */
* {
margin: 0;
padding: 0;
}
Choosing an appropriate color scheme:
This will depend on the brand color. Then you can choose complementing colors.
Brand color is your primary color, this will be more visible color. That does not mean it will be used more in design but it means it will be used where you want your user to focus on.
Here that will be our card component and buttons.
/* COLORS */
:root {
/* primary */
--brand-color: rgb(42, 38, 95);
--button: rgb(29, 24, 107);
/* neutral */
--dark: rgb(20, 16, 68);
--light: rgb(238, 237, 253);
--light-grey: rgb(211, 211, 245);
--background-blue: rgb(113, 117, 218);
}
Defining the structure and Layout:
The card should have a rectangular shape.
Generally, it has a fixed width and height.
Defining the position of the card. Here since there is only one card it should be placed at the center.
body {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.profile-card {
width: 350px;
padding: 3rem 0rem 0rem 0rem;
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
border-radius: 14px;
background-color: var(--light);
}
Use compelling typography:
- we use
font-face
to add that,
- we use
/* FONTS */
@font-face {
font-family: 'Roboto';
src: url(../assets/fonts/Roboto-Regular.ttf);
font-weight: 400;
}
@font-face {
font-family: 'Roboto';
src: url(../assets/fonts/Roboto-Bold.ttf);
font-weight: 700;
}
body {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
font-family: 'Roboto';
font-weight: 400;
font-size: 0.9rem;
color: var(--light-grey);
background-color: var(--background-blue);
}
Styling all other elements, while styling keep these points in mind
keep the corner round, roundness may vary, it make it look soft(use border-radius).
vary
font-size
andfont-weight
such that it makes hierarchy visible.
.profile-pic {
padding: 5px;
width: 160px;
border-radius: 90px;
filter: brightness(70%);
border: 3px solid var(--brand-color)
}
.details {
padding: 1rem;
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
background-color: var(--brand-color);
border-radius: 0px 0px 14px 14px;
}
.name {
font-size: 1.3rem;
font-weight: 700;
color: white;
margin-bottom: 20px;
}
.location {
display: flex;
align-items: center;
gap: 10px;
}
.location img {
height: 1rem;
filter: invert();
}
.button {
width: 70%;
display: flex;
justify-content: space-around;
}
.button button {
width: 100px;
padding: 0.8rem 1.2rem;
border: none;
background-color: var(--dark);
color: var(--light);
border-radius: 5px;
}
.skills {
margin-top: 30px 0px;
padding: 1rem 0rem;
border-top: 2px solid var(--dark);
}
.skills h2 {
padding: 0.3rem 1rem;
font-size: 1rem;
font-weight: 700;
color: white;
}
.skills-list {
list-style: none;
margin: 0px;
padding: 0px;
}
.skills-list li {
cursor: pointer;
padding: 0.1rem 1rem;
margin: 2px 0px;
font-size: 0.8rem;
border-radius: .4rem;
display: inline-block;
color: var(--light);
}
Adding shadow:
- adding shadow using box-shadow adds a 3d effect, it gives depth to the element. It creates a huge difference.
Interaction and responsive:
adding effects on hover for interaction
for responsiveness, there is not much to do in this project
.skills-list li:hover {
transform: translateY(-5px);
color: var(--dark);
background-color: var(--background-blue);
}
.button button:hover {
transform: translateY(-3px);
color: white;
background-color: var(--button);
}
.profile-pic:hover {
transform: translateY(-5px);
filter: brightness(100%);
}
Final CSS code
/* GLOBAL */
* {
margin: 0;
padding: 0;
}
/* FONTS */
@font-face {
font-family: 'Roboto';
src: url(../assets/fonts/Roboto-Regular.ttf);
font-weight: 400;
}
@font-face {
font-family: 'Roboto';
src: url(../assets/fonts/Roboto-Bold.ttf);
font-weight: 700;
}
/* COLORS */
:root {
/* primary */
--brand-color: rgb(42, 38, 95);
--button: rgb(29, 24, 107);
/* neutral */
--dark: rgb(20, 16, 68);
--light: rgb(238, 237, 253);
--light-grey: rgb(211, 211, 245);
--background-blue: rgb(113, 117, 218);
}
body {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
font-family: 'Roboto';
font-weight: 400;
font-size: 0.9rem;
color: var(--light-grey);
background-color: var(--background-blue);
}
.profile-card {
width: 350px;
padding: 3rem 0rem 0rem 0rem;
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
border-radius: 14px;
background-color: var(--light);
box-shadow: 0px 3px 8px var(--dark);
}
.profile-pic {
padding: 5px;
width: 160px;
border-radius: 90px;
filter: brightness(70%);
border: 3px solid var(--brand-color)
}
.profile-pic:hover {
transform: translateY(-5px);
filter: brightness(100%);
}
.details {
padding: 1rem;
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
background-color: var(--brand-color);
border-radius: 0px 0px 14px 14px;
}
.name {
font-size: 1.3rem;
font-weight: 700;
color: white;
margin-bottom: 20px;
}
.location {
display: flex;
align-items: center;
gap: 10px;
}
.location img {
height: 1rem;
filter: invert();
}
.button {
width: 70%;
display: flex;
justify-content: space-around;
}
.button button {
width: 100px;
padding: 0.8rem 1.2rem;
border: none;
background-color: var(--dark);
color: var(--light);
border-radius: 5px;
box-shadow: 0px 1px 3px 0px black;
}
.button button:hover {
transform: translateY(-3px);
color: white;
background-color: var(--button);
}
.skills {
margin-top: 30px 0px;
padding: 1rem 0rem;
border-top: 2px solid var(--dark);
}
.skills h2 {
padding: 0.3rem 1rem;
font-size: 1rem;
font-weight: 700;
color: white;
}
.skills-list {
list-style: none;
margin: 0px;
padding: 0px;
}
.skills-list li {
cursor: pointer;
padding: 0.1rem 1rem;
margin: 2px 0px;
font-size: 0.8rem;
border-radius: .4rem;
display: inline-block;
color: var(--light);
}
.skills-list li:hover {
transform: translateY(-5px);
color: var(--dark);
background-color: var(--background-blue);
}
Final Card Component
Conclusion
This is the process I follow while building most of the components. If you keep all the points in the article you are good to go. Try building more and more projects. Practice is the only way to get these right.
I practice from fontendmentor. You can give it a try.
For any suggestions comment below. Thank you for reading