Skip to content

Commit f252a9a

Browse files
committed
Done project practice
1 parent 2fbef2d commit f252a9a

File tree

4 files changed

+363
-2
lines changed

4 files changed

+363
-2
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
title: "CSS Animation Practice Projects"
3+
sidebar_label: Animation Practice
4+
description: "Hands-on CSS animation practice with real mini-projects, transitions, keyframes, micro-interactions, and modern UI animation patterns."
5+
keywords: [CSS animation practice, CSS transitions projects, CSS keyframes tutorial, CSS transforms practical, animated buttons, loading spinners, moving background]
6+
tags:
7+
[
8+
css,
9+
animations,
10+
transitions,
11+
keyframes,
12+
micro-interactions,
13+
ui-design,
14+
frontend,
15+
beginner,
16+
advanced,
17+
practice,
18+
codeharborhub,
19+
]
20+
---
21+
22+
Animations are the secret ingredient that transforms a static webpage into an **engaging and memorable user experience**. This practical session is dedicated to solidifying your understanding of CSS **Transitions**, **Transforms**, and **Keyframe Animations** by applying them to real-world components.
23+
24+
Before starting, ensure you are familiar with the concepts in the [Transitions and Animations](/tutorial/category/transitions--animations) section.
25+
26+
<AdsComponent />
27+
<br />
28+
29+
## Project 1: The Interactive 3D Button (Transforms & Transitions)
30+
31+
This project focuses on combining CSS **Transforms** for 3D effects with **Transitions** for a smooth, interactive feel.
32+
33+
### The Goal
34+
35+
Create a button that appears to "press down" or "lift up" when hovered over.
36+
37+
<CodePenEmbed
38+
title="The Interactive 3D Button (Transforms & Transitions)"
39+
penId="emZxGLa"
40+
/>
41+
42+
## Project 2: A Simple CSS Loading Spinner (Keyframes)
43+
44+
A classic use of CSS animations is creating loading indicators. This project uses the fundamental **Keyframes** and the `animation` shorthand property.
45+
46+
### The Goal
47+
48+
Create a perpetually rotating, border-based loading spinner.
49+
50+
<CodePenEmbed
51+
title="A Simple CSS Loading Spinner (Keyframes)"
52+
penId="myPvBaM"
53+
/>
54+
55+
## Project 3: Background Color Pulse Effect (Keyframes & Iteration Count)
56+
57+
This project demonstrates how to use **Keyframes** for a subtle, repeating change, perfect for drawing attention to a new notification or a primary call-to-action.
58+
59+
### The Goal
60+
61+
Create a small badge that smoothly pulses between two background colors.
62+
63+
<CodePenEmbed
64+
title="Background Color Pulse Effect (Keyframes & Iteration Count)"
65+
penId="OPNdxdQ"
66+
/>
67+
68+
## Project 4: Creating a "Water Wave" Background (Complex Keyframes)
69+
70+
This advanced project combines multiple properties (`transform`, `opacity`, `filter`) within keyframes to create a complex, moving visual effect, simulating a water or gradient wave.
71+
72+
### The Goal
73+
74+
Animate a large pseudo-element to create a constantly moving, subtle wave-like background effect.
75+
76+
<CodePenEmbed
77+
title="Creating a Water Wave Background (Complex Keyframes)"
78+
penId="jEqdGRX"
79+
/>
80+
81+
## Your Challenge
82+
83+
Take what you've learned and build the following:
84+
85+
1. **Animated Menu Icon (Hamburger to 'X'):** Use CSS **Transforms** (`rotate`, `translate`) and **Transitions** to smoothly transform a three-line hamburger menu icon into an 'X' symbol when a parent container is hovered.
86+
2. **Slide-In Notification:** Create a notification bar that slides into view from the top of the screen using **Keyframes** to animate the `transform: translateY()` property. The animation should run only once when the page loads (`animation-iteration-count: 1`).
87+
88+
<AdsComponent />
89+
<br />
90+
91+
## Key Takeaways
92+
93+
* **Transitions** are best for **state changes** (like `:hover`, `:focus`).
94+
* **Keyframes** are essential for **automatic, continuous, or sequential animations**.
95+
* The `transform` property is your most powerful tool for performant animations, especially `translate`, `rotate`, and `scale`.
96+
* Using `alternate` in your `animation-direction` can create seamless, back-and-forth animations without harsh jumps.
97+
98+
Ready to test your skills on the next big area?

docs/css/project-practicals/layout-practice.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,29 @@ Centered Box
402402
Try customizing these layouts by changing colors, spacing, and adding more elements. Experiment with different layout techniques to see how they affect the design and responsiveness of your pages.
403403
:::
404404

405+
## Additional Resources for Practice
406+
407+
* **[Dev Snap](https://devsnap.me/css-grid-examples):** A collection of community-driven code snippets featuring grids, layouts, and interactive designs. Many examples include subtle animations you can study and reuse in your own projects.
408+
409+
410+
* **[Animista](https://animista.net):** A visual playground for exploring different animation styles such as fades, flips, rotations, zooms, entrances, exits, shadows, and text effects. You can customize animations and copy clean CSS instantly.
411+
412+
* **[CSS-Tricks](https://css-tricks.com):** This site provides deep-dive articles on CSS transitions, easing, smoothing, keyframes, performance tips, and advanced animation workflows. Great for understanding *why* animations work the way they do.
413+
414+
* **[MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/CSS/animation):** The most reliable and complete documentation for properties like `animation`, `transition`, `transform`, and `@keyframes`. Includes browser support tables and real examples.
415+
416+
* **[LottieFiles](https://lottiefiles.com):** Use rich vector animations powered by Lottie. Ideal for modern hero sections, onboarding screens, loading animations, and app interfaces.
417+
418+
* **[Easing Functions Cheat Sheet](https://easings.net):** A complete guide to easing curves with visual previews. Helps you choose the perfect timing function for smoother and more natural animations.
419+
420+
* **[GreenSock (GSAP)](https://gsap.com):** For complex, high-performance animations, GSAP is the industry standard. Ideal for scroll animations, timeline-based motion, stagger effects, and chaining.
421+
422+
* **[CodePen](https://codepen.io/search?q=css+animation):** A massive collection of community-built animations. Perfect for inspiration and hands-on practice by remixing pens.
423+
424+
* **[UI Snippets](https://uiverse.io/):** Provides modern animated UI components like buttons, loaders, cards, toggles, and input interactions. All examples are editable and use pure HTML/CSS.
425+
426+
* **[Cubic-Bezier.com](https://cubic-bezier.com):** Visually design custom cubic-bezier easing curves and instantly preview how your animation will feel.
427+
405428
## Summary
406429

407430
This module provided hands-on practice with essential CSS layout techniques using Flexbox and Grid. By building real-world layouts like navigation bars, dashboards, hero sections, and responsive grids, you can enhance your frontend development skills and create visually appealing web pages.
Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,161 @@
1-
<ComingSoon />
1+
---
2+
title: "CSS Performance Optimization Practice"
3+
labal: "CSS Performance Optimization"
4+
description: "Practical exercises and techniques to optimize CSS, focusing on reducing rendering time, improving page load speed, and boosting overall performance."
5+
keywords: [CSS performance optimization, critical CSS, reducing repaint, minimizing reflow, efficient selectors, CSS project performance]
6+
tags: [CSS performance optimization, critical CSS, reducing repaint, minimizing reflow, efficient selectors, CSS project performance]
7+
---
8+
9+
Writing performant CSS is essential for a fast, smooth user experience. Poorly structured or oversized CSS can lead to slow page loads, janky scrolling, and poor interaction responsiveness.
10+
11+
This practical guide moves beyond theory, providing concrete steps and code examples to ensure your stylesheets are as lean and fast as possible, focusing on minimizing browser work.
12+
13+
<AdsComponent />
14+
<br />
15+
16+
## Project 1: Reducing Browser Reflow and Repaint
17+
18+
**Reflow** (or Layout) is the browser recalculating the layout of elements. **Repaint** is the browser redrawing the pixels on the screen. Both are costly, and CSS is often the culprit.
19+
20+
### The Goal
21+
22+
Optimize a simple animation to prevent costly Reflows, using the most performant CSS properties.
23+
24+
### The Problem Code (Reflow Trigger)
25+
26+
Animating properties like `width`, `height`, `top`, `left`, `margin`, and `padding` triggers a Reflow.
27+
28+
```css title="❌ AVOID: Triggers Reflow and Repaint on every frame" showLineNumbers
29+
.box-problem {
30+
width: 100px;
31+
height: 100px;
32+
background-color: red;
33+
transition: width 0.5s, height 0.5s;
34+
}
35+
36+
.box-problem:hover {
37+
width: 200px; /* Reflow trigger */
38+
height: 200px; /* Reflow trigger */
39+
}
40+
````
41+
42+
### The Solution Code (Performant)
43+
44+
The properties `transform` and `opacity` are ideal for high-performance animations because they are handled by the browser's **compositor thread**, minimizing Reflow and Repaint. They often lead to **GPU acceleration**.
45+
46+
```css title="✅ USE: Only triggers Repaint (and ideally, only Compositing)" {6-9,16} showLineNumbers
47+
.box-solution {
48+
width: 100px;
49+
height: 100px;
50+
background-color: green;
51+
52+
/* Use scale() instead of changing width/height */
53+
transform: scale(1);
54+
/* Hint the browser to prepare for animation */
55+
will-change: transform;
56+
57+
transition: transform 0.5s ease-out;
58+
}
59+
60+
.box-solution:hover {
61+
/* Only modifies the transform property */
62+
transform: scale(1.5);
63+
}
64+
```
65+
66+
## Project 2: Writing Efficient Selectors
67+
68+
The browser reads CSS selectors from **right to left** (the "key selector"). Inefficient selectors force the browser to check too many elements, slowing down styling.
69+
70+
### The Goal
71+
72+
Rewrite inefficient selectors to be faster and more targeted.
73+
74+
### Inefficient Selectors (Right-to-Left Matching)
75+
76+
The browser first finds **all** `div` elements, then checks if their parent is a `section`, and so on.
77+
78+
```css showLineNumbers
79+
/* ❌ INEFFICIENT: The key selector is 'div' */
80+
section div.card > p:nth-child(2) {
81+
/* ... */
82+
}
83+
84+
/* ❌ INEFFICIENT: The universal selector '*' is the key selector */
85+
#main-content * {
86+
/* ... */
87+
}
88+
```
89+
90+
### Efficient Selectors
91+
92+
Use the key selector to be as specific as possible. Class names are the fastest key selectors.
93+
94+
```css
95+
/* ✅ EFFICIENT: The key selector is '.card__paragraph' */
96+
.card__paragraph {
97+
/* ... */
98+
}
99+
100+
/* ✅ EFFICIENT: Targets only the specific class within the section */
101+
section .card-item {
102+
/* ... */
103+
}
104+
105+
/* ✅ EFFICIENT: Simple ID selector */
106+
#footer {
107+
/* ... */
108+
}
109+
```
110+
111+
:::tip Best Practice
112+
Favor single class selectors over complex nested or attribute selectors, especially for your "key selector" (the rightmost part of the rule). Using methodologies like BEM (Block, Element, Modifier) inherently promotes fast, single-class selectors.
113+
:::
114+
115+
## Project 3: Utilizing the `will-change` Property
116+
117+
The `will-change` property is a CSS hint for the browser. It tells the browser which properties you intend to change on an element *before* the change happens, allowing it to apply expensive optimizations (like creating a new layer).
118+
119+
### The Goal
120+
121+
Apply `will-change` strategically to an element that will be animated on hover.
122+
123+
<CodePenEmbed
124+
title="Utilizing the `will-change` Property"
125+
penId="azNXVgL"
126+
/>
127+
128+
:::warning
129+
Only apply `will-change` just before the animation/transition starts, and remove it afterward. Applying it permanently can waste the browser's resources. In the example above, we apply it permanently because it's only two minor properties, but for large, complex animations, manage it with JavaScript or a state-based class.
130+
:::
131+
132+
## Project 4: Implementing Critical CSS (Theory & Setup)
133+
134+
**Critical CSS** is the minimal, blocking CSS required to render the visible portion of the webpage ("above the fold") instantly. The rest of the CSS is loaded asynchronously (non-blocking). This dramatically improves the *Perceived Performance*.
135+
136+
### The Goal
137+
138+
Understand the principle and workflow for separating Critical CSS.
139+
140+
### Workflow
141+
142+
1. **Identify Critical CSS:** Use a tool (like **Penthouse** or the **Critical** NPM package) to analyze your HTML/CSS and extract the essential styles needed for the initial viewport view.
143+
2. **Inline Critical CSS:** Place this small block of CSS directly inside the `<style>` tags within your HTML's `<head>`.
144+
3. **Asynchronously Load Remaining CSS:** Load the full, larger stylesheet using techniques that prevent blocking (e.g., using a `<link rel="preload">` followed by a JavaScript change to `<link rel="stylesheet">`).
145+
146+
## Your Challenge
147+
148+
1. **Audit Your Code:** Use your browser's DevTools (**Performance** tab) to record a page load. Look for "Layout" and "Recalculate Style" events. Try to identify a performance bottleneck in your CSS.
149+
2. **Optimize an Image Slider:** If you have an image slider that uses `left` or `margin-left` to transition between slides, refactor it to use `transform: translateX()` for smooth, performant sliding.
150+
151+
<AdsComponent />
152+
<br />
153+
154+
## Key Takeaways
155+
156+
| Technique | Goal | Performance Impact |
157+
| :--- | :--- | :--- |
158+
| **`transform` / `opacity`** | Animation | High performance; GPU-accelerated (Compositing). |
159+
| **Efficient Selectors** | Initial Parsing | Faster browser style calculation time. |
160+
| **Critical CSS** | Perceived Performance | Fastest time to first paint (TTFP) and Largest Contentful Paint (LCP). |
161+
| **`will-change`** | Animation | Tells the browser to prepare for upcoming costly animations. |
Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,81 @@
1-
<ComingSoon />
1+
---
2+
title: "Responsive Design Practice Projects"
3+
labal: "Responsive Design Practice"
4+
description: "Master CSS Responsive Design by implementing Media Queries, Fluid Layouts, and Mobile-First approaches in practical projects."
5+
keywords: [CSS responsive design practice, media queries project, mobile-first design tutorial, fluid layouts CSS, responsive image gallery]
6+
---
7+
8+
Responsive Web Design (RWD) is a crucial skill in modern frontend development. It ensures your website looks and performs well across a wide range of devices—from small mobile phones to large desktop monitors.
9+
10+
This practical session will guide you through implementing the core principles of RWD, focusing on **Media Queries**, **Fluid Layouts**, and the **Mobile-First** strategy.
11+
12+
Before starting, ensure you are familiar with the concepts in the [Responsiveness](/tutorial/category/responsiveness) section.
13+
14+
<AdsComponent />
15+
<br />
16+
17+
## Project 1: Building a Responsive Navigation Bar (Mobile-First)
18+
19+
The Mobile-First approach is the industry standard. We start by designing for the smallest screen and add complexity (and wider layouts) as the screen size increases.
20+
21+
### The Goal
22+
23+
Create a simple navigation bar that is stacked vertically on mobile and horizontally aligned on desktops.
24+
25+
<CodePenEmbed
26+
title="Building a Responsive Navigation Bar (Mobile-First)"
27+
penId="MYyLOWM"
28+
/>
29+
30+
## Project 2: A Fluid and Responsive Image Gallery (Flexbox & Media Queries)
31+
32+
Creating responsive grids is the most common use case for RWD. We'll use Flexbox for layout flexibility combined with Media Queries to control the number of columns.
33+
34+
### The Goal
35+
36+
Create an image gallery where images display:
37+
38+
* **1 column** on mobile.
39+
* **2 columns** on tablets.
40+
* **4 columns** on desktops.
41+
42+
<CodePenEmbed
43+
title="A Fluid and Responsive Image Gallery (Flexbox & Media Queries)"
44+
penId="gbrqXae"
45+
/>
46+
47+
## Project 3: Responsive Typography and Images (Viewport Units & Fluidity)
48+
49+
True fluidity means scaling elements based on the viewport size, not just fixed breakpoints.
50+
51+
### The Goal
52+
53+
1. Make the main heading font size scale smoothly with the viewport width.
54+
2. Ensure images never overflow their container and scale down gracefully.
55+
56+
<CodePenEmbed
57+
title="Responsive Typography and Images (Viewport Units & Fluidity)"
58+
penId="ByKMmzO"
59+
/>
60+
61+
## Your Challenge
62+
63+
Combine the techniques above to build a complete **responsive pricing card layout**:
64+
65+
1. **Mobile View:** Pricing cards should be stacked vertically (1-column).
66+
2. **Tablet View:** Pricing cards should be arranged horizontally in a 2-column grid.
67+
3. **Desktop View:** Pricing cards should be arranged horizontally in a 3-column grid.
68+
4. **Fluidity:** Use viewport units for a subtle element (e.g., the price number) and ensure all content remains readable at all breakpoints.
69+
70+
<AdsComponent />
71+
<br />
72+
73+
## Key Takeaways
74+
75+
* **Mobile-First (`min-width`):** Write CSS for mobile first, then use `min-width` media queries to apply larger screen styles. This loads less CSS for mobile users.
76+
* **The Viewport Meta Tag:** Always include this in your HTML `<head>` for proper scaling:
77+
```html
78+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
79+
```
80+
* **Fluid Units:** Embrace relative units (`%`, `em`, `rem`) and modern units (`vw`, `vh`, `clamp()`) over fixed pixels where scaling is desired.
81+
* **Image Fluidity:** The key responsive image CSS is `max-width: 100%; height: auto;`.

0 commit comments

Comments
 (0)