๐ŸŽจ 3. Cascading Style Sheets (CSS)

CSS controls the visual presentation of web pages โ€” layout, colors, typography, animations, and responsive behavior. This section demonstrates core CSS concepts with live, interactive examples.

๐Ÿ“Œ Three Ways to Apply CSS

Inline: <p style="color:red;"> โ†’ This text uses inline color.

Internal / External: Best practice uses external stylesheets. This page uses internal & external concepts (embedded & global).

<link rel="stylesheet" href="styles.css">   โ† external (reusable)

๐ŸŽฏ Selectors (Class, ID, Combinators)

๐Ÿ”ต This paragraph uses a class selector (.example).

๐ŸŸข This uses an ID selector (#unique-selector-demo) โ€“ border left accent.

๐Ÿ“Œ Descendant selector: inside a div โ†’ targeted by .demo-container p.

๐Ÿ“ฆ CSS Box Model

๐Ÿงฉ Box Model
Hover โ†’ padding/border grow

Every element is a rectangle: content โ†’ padding โ†’ border โ†’ margin.

๐Ÿ“ Flexbox โ€” One-dimensional layout

HTML
CSS
JS
React
Node

โœจ Hover items โ†’ translateY & shadow. Flex properties: justify-content: center; flex-wrap: wrap;

๐Ÿ”ฒ CSS Grid โ€” Two-dimensional layout

Grid 1
Grid 2
Grid 3
Grid 4
Grid 5
Grid 6

grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)) โ†’ responsive columns.

โœจ Animations & Transitions

CSS
Anim

โฌ†๏ธ Button uses transition on hover (background, letter-spacing, scale). Circle uses @keyframes pulseGlow infinite.

๐ŸŽ›๏ธ CSS Custom Properties (Variables)

:root {
    --primary-color: #1a1a2e;
    --accent-color: #e94560;
    --border-radius: 20px;
}
This box uses var(--accent-color) and var(--border-radius) from root.

โœ… CSS variables allow dynamic theming and easy maintenance.

๐ŸŽญ Pseudo-classes (:hover, :focus) & Pseudo-elements (::before)

Hover over me

::before adds an emoji on hover; :hover changes background & padding.

Other pseudo-classes: :first-child, :nth-of-type, :focus (input focus effects).

๐Ÿ“ฑ Responsive Design โ€” Media Queries

๐Ÿ” Resize your browser window! Background & text indicator changes based on viewport width.

Media queries apply different styles at breakpoints (e.g., @media (max-width: 680px)). This portfolio also adapts navigation, padding, and grid layout on mobile.

Current viewport indicator: Resize to see change

โš–๏ธ Specificity & Cascade

CSS rules are applied based on specificity: inline > ID > class > element. Important: !important overrides, but use sparingly.

This paragraph has inline color: green but also a class? Inline wins.

โ†’ Result: Inline style (> class) makes text green. Demonstrates cascade priority.

๐ŸŒˆ Gradients & Backgrounds

โœจ Linear Gradient (dark to accent)
Radial gradient

๐Ÿ’ก CSS brings life to HTML and is essential for front-end and full stack developers. This page demonstrates layout models, animations, responsiveness, and modern techniques used in real-world projects.

โฌ† Back to top