Welcome to Day 7 of your CSS Learning Experience! Today’s tutorial will highlight one of the most exciting and practical aspects of modern web development, Responsive Design.
Have you ever wondered how all of these websites are so magically responsive and look perfect on your phone, tablet, and computer? It’s all because of responsive design! In this tutorial, you’d build a beautiful responsive Profile Card that is interactive and looks great on every screen.
Why should students and beginners care about Responsive Design?
In the end, you would know how to use media queries to create a mobile first page and add polish and sophistication with pseudo-elements.
First, let’s establish the basic structure of our project using valid HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Responsive Profile Card</title>
<link rel="stylesheet" href="day7.css">
</head>
<body>
<form>
<label for="fileupload">upload file</label>
<input type="file" id="fileupload"/>
</form><br>
<div class="card">
<h2>NioTechone🎀</h2>
<p>Frontend Developer</p>
</div>
</body>
</html>
What’s going on here?
Pro Tip: Always make sure to add the viewport meta tag in the <head> section of any responsive website you build as the first rule of mobile-friendly design!
Next, we will begin our CSS with a reset using the universal selector:
* { margin: 0; padding: 0; box-sizing: border-box; }
Why do we need this?
Note: Think of box-sizing: border-box like packing a suitcase. With this property, the suitcase stays the same size, even when you pack clothes (padding) inside!
Now let’s create a stunning background and center our content
body {
font-family: 'Poppins', Arial, sans-serif;
background: linear-gradient(135deg, #a8edea, #fed6e3);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
color: #333;
padding: 20px;
}
Breaking it down:
Pro Tip: Using vh (viewport height) and vw (viewport width) units makes your design truly responsive. 100vh is always going to equal the full height of the screen, regardless if it is a phone or a 4K monitor!
Let’s style the form, so even a basic file input looks polished:
form {
background: #fff;
padding: 20px 30px;
border-radius: 12px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
margin-bottom: 30px;
text-align: center;
}
label {
font-weight: 600;
color: #444;
margin-right: 10px;
}
input[type="file"] {
padding: 8px;
font-size: 1rem;
border: 2px solid #2575fc;
border-radius: 8px;
background-color: #f0f4ff;
cursor: pointer;
transition: 0.3s ease;
}
input[type="file"]:hover {
background-color: #e0e7ff;
border-color: #6a11cb;
}
Breaking it down:
Note: The :hover pseudo-class is different from pseudo-elements (::before, ::after). Pseudo-classes select an element in one specific state, while pseudo-elements create virtual elements.
Let’s start designing our primary profile card:
.card {
background: #fff;
border-radius: 15px;
padding: 40px 60px;
text-align: center;
width: 300px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
transition: all 0.3s ease;
}
.card:hover {
transform: translateY(-8px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
background: linear-gradient(145deg, #ffffff, #f6f6f6);
}
.card h2 {
font-size: 1.8rem;
color: #6a11cb;
margin-bottom: 8px;
}
.card p {
font-size: 1.1rem;
color: #555;
font-weight: 500;
}
What makes this card special?
Pro Tip: Use rem rather than px for font sizing. 1rem is the root font size (generally speaking, 16px). So, rem units scale better for accessibility when a user alters their browser font size!
Now, here is where we make everything responsive to the viewport/resolution! This is the most important part of today’s topic:
@media (max-width: 600px) {
form {
width: 90%;
}
.card {
width: 90%;
padding: 30px 20px;
}
.card h2 {
font-size: 1.5rem;
}
.card p {
font-size: 1rem;
}
}
Learning media queries:
What will happen in mobile:
Note: we refer to this method as mobile-first design when writing base styles for mobile devices and then using media queries for larger devices. Our example uses a desktop-first approach (base styles for desktop, and media query styles for mobile devices). Either approach is good practice, but mobile-first design is now considered best practice!
Common breakpoints you should know:
Throughout this project, we utilized viewport units (vh, vw):
body {
min-height: 100vh;
padding: 20px;
}
Here’s how viewport units are defined:
Why do I find these units better than using percentages:
This makes them suitable to use for full page sections and spacing that is responsive
We used transitions throughout project:
.card {
transition: all 0.3s ease;
}
Here is a breakdown of the syntax:
Here are some others you could use:
Pro Tip: Don’t animate all properties on production code! Less performant. Instead, be specific about what you are animating. For example: transition: transform 0.3s ease, box-shadow 0.3s ease;
We created depth using box-shadow:
.card {
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}
```
**Box-shadow syntax:**
```
box-shadow: [horizontal] [vertical] [blur] [spread] [color];
How to create realistic shadows:
Although we are not using pseudo-elements in our project, they are included as part of the topic today. Here is how you could embed begins:
.card h2::before {
content: "👤 ";
}
.card h2::after {
content: " ✨";
}
What are pseudo-elements?
Common uses for this are:
1. Components / Keywords Used
Name | Description |
@media | CSS rule that applies styles based on device characteristics (screen size, orientation, etc.) |
max-width | Media query condition that triggers when viewport is at or below specified width |
min-height | Sets the minimum height; element can grow taller but never shorter than this value |
viewport meta tag | HTML tag that controls how mobile browsers display the page |
box-sizing | Controls how width/height calculations include padding and borders |
linear-gradient() | Creates smooth color transitions across an element |
translateY() | Moves an element vertically without affecting document flow |
transition | Smoothly animates property changes over a specified duration |
box-shadow | Creates shadow effects to add depth and elevation |
:hover | Pseudo-class that applies styles when user hovers over element |
rem | Relative unit based on root font size (more accessible than px) |
vh (viewport height) | Unit equal to 1% of viewport height (100vh = full screen height) |
rgba() | Color function with red, green, blue, and alpha (opacity) values |
2. Key Properties / Parameters / Features
Name | Description |
width: device-width | Makes viewport width match device screen width (critical for mobile) |
initial-scale=1 | Sets initial zoom level to 100% on mobile devices |
border-radius | Rounds corners of elements; higher values = rounder corners |
padding | Inner spacing between content and border |
margin | Outer spacing between element and neighbors |
flex-direction: column | Stacks flex items vertically instead of horizontally |
align-items: center | Centers flex items along cross axis (horizontally in columns) |
justify-content: center | Centers flex items along main axis (vertically in columns) |
font-weight | Controls text boldness (300=light, 400=normal, 600=semi-bold, 700=bold) |
cursor: pointer | Changes mouse cursor to hand icon indicating clickability |
text-align: center | Centers text and inline elements horizontally |
background | Sets background color, image, or gradient |
transform | Applies 2D or 3D transformations (translate, rotate, scale, skew) |
Breakpoint (600px) | Screen width threshold where layout changes for mobile devices |
Here are some great ways to help you learn about responsive design and CSS:
Official Documentation:
Learning Platforms:
Practice Platforms:
Tools & Generators:
Video Tutorials:
Source code:
Day 7 taught you how to make websites fully responsive using media queries, viewport units, and pseudo-elements. You built a responsive profile card that adjusts for mobile screens, added hover effects, and learned how :: before, :: after, and breakpoints make layouts modern and mobile-friendly.
CSS pseudo-elements allow you to style interior portions of an element such as the first line, first letter, before and after content. The following are pseudo-elements:
No, Pseudo-elements can only be used to insert text, emoji, or generated content using the content: property, not real HTML tags.
Media queries allow websites to cater to different screen sizes so that your layout looks great on a laptop, tablet, or smartphone.
Responsive design is a method of making pages in a way that the layout, font sizes, and content adjust automatically to any device screen, enhancing usability and UX.
Copyright © 2025 Niotechone Software Solution Pvt. Ltd. All Rights Reserved.