CSS Fundamentals Practice
This assignment helps you practice and demonstrate your understanding of CSS fundamentals through a series of mini assessments. You will work with an AI assistant to analyze code, identify issues, and explain CSS concepts. This format allows you to learn through conversation and develop your ability to articulate technical concepts.
Complete each challenge below by copying the code and AI prompt template into your preferred AI tool (ChatGPT, Claude, etc.). Have a conversation with the AI about each challenge, then submit a reflection documenting what you learned.
How to Complete This Assignment
- Read through each challenge below to understand what you need to analyze
- Attempt each challenge on your own first without AI assistance. You may copy the code to VS Code to test it, but disable any AI coding assistants while working.
- After making your best attempt, use the copy icon above each code block to copy both the code and AI prompt template
- Paste into your AI assistant (ChatGPT, Claude, etc.) and discuss your solution
- Have a conversation with the AI about your answers, asking for clarification when needed
- Move to the next challenge and repeat
- After completing all challenges, fill out the reflection form at the end
The goal is to develop your problem-solving skills first, then use AI to verify and deepen your understanding. You learn more by struggling with concepts before getting help.
Each challenge has a copy icon above the code block. You must use this copy button to copy both the code and the AI prompt template together. Simply selecting and copying the text will not work correctly. The copy button ensures the AI prompt is included with your code.
Challenge 1: Specificity Conflicts
You are helping a student understand CSS specificity. They are analyzing the code below to determine which color rules will apply to each paragraph element. They should identify the specificity of each selector (using the format 0,0,0,0) and explain which rule wins for each paragraph based on specificity. Guide them to understand specificity calculation with IDs (0,1,0,0), classes (0,0,1,0), and elements (0,0,0,1). If they make mistakes, help them understand why certain selectors are more specific than others. Do not give them direct answers immediately; ask guiding questions to help them figure it out.
/* Analyze which color applies to each paragraph element below */
p {
color: blue;
}
.intro {
color: green;
}
#special {
color: red;
}
div p {
color: purple;
}
.container .intro {
color: orange;
}
#special.intro {
color: brown;
}
Here is the HTML structure the CSS applies to:
<div class="container">
<p>Paragraph 1</p>
<p class="intro">Paragraph 2</p>
<p id="special">Paragraph 3</p>
<p id="special" class="intro">Paragraph 4</p>
</div>
<!-- HTML for reference: -->
<div class="container">
<p>Paragraph 1</p>
<p class="intro">Paragraph 2</p>
<p id="special">Paragraph 3</p>
<p id="special" class="intro">Paragraph 4</p>
</div>
Challenge 2: Box Model Calculations
You are helping a student understand the CSS box model. They need to calculate the actual rendered dimensions of two boxes with different box-sizing values. Guide them to understand that content-box adds padding and border to the specified width/height, while border-box includes padding and border within the specified dimensions. If they make calculation errors, help them see what they are missing. Ask them to show their work step by step.
/* Calculate the actual rendered dimensions */
.box-one {
box-sizing: content-box;
width: 300px;
height: 200px;
padding: 20px;
border: 5px solid black;
margin: 10px;
}
.box-two {
box-sizing: border-box;
width: 300px;
height: 200px;
padding: 20px;
border: 5px solid black;
margin: 10px;
}
Challenge 3: Cascade Order
You are helping a student understand the CSS cascade. They are analyzing multiple rules that apply to the same element to determine which background color wins. Guide them to consider both specificity and source order. When rules have the same specificity, the one appearing later in the stylesheet wins. Help them understand the relationship between specificity and cascade order. Do not simply tell them the answer; ask questions to help them reason through it.
/* Which background color applies? */
div {
background: blue;
}
.box {
background: green;
}
div {
background: red;
}
.container .box {
background: purple;
}
.box {
background: orange;
}
Here is the HTML structure the CSS applies to:
<div class="container">
<div class="box">What color am I?</div>
</div>
<div class="container">
<div class="box">What color am I?</div>
</div>
Challenge 4: Mobile-First Media Queries
You are helping a student understand mobile-first design. They are reviewing CSS code to determine if it follows mobile-first principles. Mobile-first means base styles target mobile devices, and media queries use min-width (or width greater than or equal to) to add complexity for larger screens. Desktop-first uses max-width and starts complex. Guide them to identify which approach the code uses and help them rewrite it correctly if needed. Emphasize starting simple and adding complexity.
/* Is this mobile-first? If not, fix it. */
.navigation {
display: flex;
flex-direction: row;
justify-content: space-between;
padding: 2rem;
font-size: 1.2rem;
}
@media (max-width: 768px) {
.navigation {
flex-direction: column;
padding: 1rem;
font-size: 1rem;
}
}
Challenge 5: Print Styles with Link URLs
You are helping a student create print-friendly styles. They need to write a print media query that hides navigation and displays URLs after links using CSS generated content with the attr() function. The pattern is: a::after { content: " (" attr(href) ")"; }. They should also avoid showing URLs for anchor links that start with # since those are page-internal. Guide them through this step by step, explaining how attr() retrieves HTML attribute values and how ::after creates generated content.
/* Complete the print styles */
nav {
display: flex;
gap: 1rem;
padding: 1rem;
background: #333;
}
a {
color: #0066cc;
text-decoration: none;
}
/* Add @media print rule here to:
1. Hide the nav element
2. Make links black and underlined
3. Show the URL after each link using attr()
4. Do NOT show URLs for anchor links (href starting with #)
*/
Challenge 6: Nested Media Queries
You are helping a student practice modern CSS nesting with media queries. They should convert the traditional separated media queries into nested syntax where media queries appear inside the selector block. The mobile-first pattern means base styles are for mobile, then nested media queries add complexity for larger screens. Guide them to understand the & symbol is optional in nested media queries and that indentation shows the relationship between base styles and responsive variations.
/* Rewrite using nested media queries */
.card {
padding: 1rem;
background: white;
border-radius: 8px;
}
@media (width >= 768px) {
.card {
padding: 2rem;
display: grid;
grid-template-columns: 200px 1fr;
}
}
@media (width >= 1024px) {
.card {
padding: 3rem;
grid-template-columns: 300px 1fr;
}
}
Submission
After completing all six challenges, fill out the reflection form below. Once complete, click the download button to generate a PDF and submit it through Canvas.
Grading Criteria
This assignment will be graded on:
- Completion: Evidence that you worked through all six challenges
- Understanding: Your reflection demonstrates comprehension of the concepts
- Engagement: You asked meaningful questions and explored topics in depth
- Explanation: You can articulate technical concepts clearly in your own words
The goal is to develop your understanding and your ability to communicate about CSS. Thoughtful engagement with the material is more valuable than perfect answers.