Project 1: Styled Student Profile & ID Card
Project 1: Styled Student Profile & ID Card
Congratulations on reaching Chapter 12! 🎉
Over the past 11 chapters, you have learned the core building blocks of CSS:
- Selectors and cascade rules
- Colors, gradients, and backgrounds
- The Box Model (content, padding, border, margin)
- Typography and custom web fonts
- CSS units (
rem,%,px) - Borders, rounded corners, and box shadows
- Positioning (
relative,absolute,z-index) - Centering and basic Flexbox layouts
Now, it is time to assemble these individual skills into your first complete, portfolio-ready CSS project: A modern Student Profile & ID Card!
Project Preview & Architecture 📐
Here is the visual layout of the profile card we are building:
+-------------------------------------------------------------+ | [TOP BANNER: Royal Blue & Violet Linear Gradient] | | | | +-----------------+ | | | [BADGE] PREFECT | | | | (pos: absolute) | | | +-----------------+ | | +-----------------------+ | | | CIRCULAR AVATAR | | | | (border-radius: 50%) | | | | (overlapping banner) | | | +-----------------------+ | | | | Aarav Sharma | | Head Boy | Class 10-A | | Delhi Model Senior Secondary School | | | | SKILLS & INTERESTS (Flexbox Row): | | [ Python ] [ Web Design ] [ Cricket ] [ Robotics ] | | | | ACTION BUTTONS (Flexbox Space-Between): | | [ View Marksheet ] [ Send Message ] | +-------------------------------------------------------------+
CSS Techniques Applied in This Project
- 1Box Model & Centering:
box-sizing: border-box;withmargin: 40px auto;to center the card on the page. - 2Gradients: A vibrant 135-degree
linear-gradientfor the top cover banner. - 3Overlapping Avatar:
border-radius: 50%;with a negative top margin (margin-top: -60px;) and a thick white border ring to make the portrait pop over the banner. - 4Absolute Positioning: Pinned "Head Boy / Prefect" corner ribbon badge (
position: absolute; top: 16px; right: 16px;). - 5Flexbox:
- Pill badges lined up with
display: flex; gap: 8px; flex-wrap: wrap;. - Action buttons aligned with
display: flex; gap: 12px;.
- 1Micro-interactions: Smooth hover lift with
transform: translateY(-6px);and an elevatedbox-shadow.
Complete Project Code
Create a file named student-profile-card.html in your editor and paste the following complete code:
How It Works: Key Takeaways
- 1
border-radius: 20px; overflow: hidden;on.profile-card:
Because the .card-banner has square top corners, setting overflow: hidden; on the parent card automatically clips the banner's corners to match the card's 20px curves!
- 1The Negative Margin Avatar Trick:
margin-top: -55px; pulls the avatar circle exactly 55px upwards into the gradient banner, creating that iconic modern profile card overlap!
- 1
flex: 1;on the Action Buttons:
Inside .action-group { display: flex; }, setting flex: 1 on both buttons ensures they share horizontal space 50/50 with zero math required.
Multiple Choice Questions
1. Which CSS technique is used to create the classic modern effect where the circular avatar overlaps the top banner?
A. Applying a negative top margin (margin-top: -55px;) on the avatar container B. Setting the avatar width to -100px C. Deleting the banner background D. Using display: none Answer: A Explanation: A negative margin pulls an element upwards in the normal document flow, allowing it to overlap the preceding sibling element cleanly.
2. Why is overflow: hidden; applied to the .profile-card parent container?
A. To stop the user from scrolling the card B. To ensure that the top gradient banner's sharp square corners are clipped to match the card's rounded border-radius: 20px; C. To turn the card invisible D. Because CSS requires all cards to hide overflow Answer: B Explanation: Child elements with rectangular backgrounds will poke out of parent rounded corners unless the parent has overflow: hidden; applied.
3. How does border-radius: 50%; turn a square <div> (110px $\times$ 110px) into a perfect circle?
A. It rounds every corner by half of the element's width and height, creating a continuous curved circle B. It converts the HTML element into an SVG image C. It compresses the pixels by 50% D. It rotates the box 360 degrees Answer: A Explanation: Applying 50% border-radius to an element with equal width and height curves the edges completely into a perfect circle.
4. What does setting flex: 1; accomplish on the two action buttons inside .action-group { display: flex; }?
A. It makes button 1 bigger than button 2 B. It forces both buttons to grow equally to fill the entire horizontal width of the card C. It stacks the buttons on top of each other D. It hides the secondary button Answer: B Explanation: When siblings in a flex container all have flex: 1, they share all available space along the main axis equally.
5. Why is position: relative; placed on .profile-card when the "Head Boy" status badge has position: absolute;?
A. To make the badge spin on hover B. To serve as the coordinate boundary anchor so the badge positions relative to the card rather than flying across the whole web page C. To prevent the badge from having text D. Because absolute badges only accept yellow colors without relative parents Answer: B Explanation: An absolute child measures its top and right offsets from its nearest positioned ancestor. Making the card position: relative traps the badge neatly inside the top corner of the card.
Practice Challenge (Try It Yourself)
- 1Open
student-profile-card.htmlin your editor. - 2Customize the card with your own name, grade, favorite school subjects, and sports!
- 3Add a second badge on the top-left corner displaying your House color (e.g., Red House or Emerald House)!
- 4Test the card on your mobile phone to verify that the card adapts cleanly to smaller touchscreens! 🎯
Project 2: Simple School Club Landing Page
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Intro to Flexbox: The Modern 1D Layout Powerhouse | Project 2: Simple School Club Landing Page |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.