CSS Web Programming Basics
CSS Overview & Implementation
Cascading Style Sheets (CSS): A stylesheet language used to describe the presentation and layout of HTML documents.
Implementation Methods:
Inline: Defined directly on an HTML element via the
styleattribute.Internal: Created using
<style>elements within the document<head>.External: Authored in a separate
.cssfile and linked in the<head>using<link rel="stylesheet" href="...">.
Selectors & Syntax

CSS Rule Structure: Consists of a selector targeting elements and a declaration block of key-value property pairs wrapped in curly braces
{}.Simple Selectors:
Universal (
*): Matches all HTML elements in the document.Type: Targets elements directly by tag name (e.g.,
p,h1).Class (
.className): Targets elements matching a specificclassattribute.ID (
#idName): Targets a unique element with a specificidattribute.Attribute (
[element]): Targets elements based on attribute presence or value.Grouping (
h1, h2, p): Applies shared styles to multiple comma-separated selectors.
Pseudo-Selectors:
Pseudo-Classes (
:pseudo-class): Apply styles based on element state or context (e.g.,:hover,:focus,:active,:first-child,:nth-child(),:disabled,:checked).Pseudo-Elements (
::pseudo-element): Target specific parts of an element or insert content (e.g.,::before,::after,::first-letter,::first-line,::placeholder,::selection,::marker).
Box Model & Display Types

Box Model Layers:
Content Box: The region where text or child elements reside.
Padding Box: Space surrounding the content box; inherits the element's background.
Border Box: Frame encompassing the padding box, defined by border properties.
Margin Box: Outer transparent spacing separating the element from surrounding boxes.
Sizing Concepts:
Intrinsic Sizing: Box size adjusts automatically based on its contained content.
Extrinsic Sizing: Box size is strictly determined by explicit CSS dimensions.
Default Box Sizing: User agent stylesheets set
box-sizing: content-boxby default, applyingwidthandheightsolely to the content box while adding padding and borders externally.
Display Properties:
block: Starts on a new line and occupies full container width.inline: Flows along with text and ignores vertical box properties likeheightor verticalmargin.inline-block: Flows inline while accepting explicit width, height, padding, and margin properties.
Inheritance
Inherited Properties by Default: Text and typography-related styles naturally inherit from parent to child elements (e.g.,
color,font-family,line-height).Non-Inherited Properties: Layout and box-model properties do not inherit by default (e.g.,
margin,padding,border,width,height).Forcing Inheritance: Properties can be manually forced to inherit using
property: inheritorall: inherit.
Color Representations
Named Keywords: Predefined CSS color terms (e.g.,
red,tan,rebeccapurple,transparent).Hexadecimal (HEX): Uses base-16 ranges (, ) translating to channel values :
6-digit:
#RRGGBB(e.g.,#000000for black,#fffffffor white).8-digit (Alpha):
#RRGGBBAA(e.g.,#00000080for opacity).
RGB / RGBA:
Standard syntax:
rgb(red green blue)orrgb(r, g, b)using integers or percentages .Alpha syntax:
rgb(r g b / alpha)orrgba(r, g, b, alpha)where alpha ranges from to or to .
HSL Format:
hsl(hue saturation lightness)Hue: Color position on the color wheel ( = red, = blue).
Saturation: Color intensity ( = grayscale, = full color).
Lightness: Brightness level ( = black, = white).
Sizing Units
Percentages (
%): Relative to parent element dimensions.Absolute Lengths (Fixed References):
px(Pixels): .in(Inches): .cm(Centimeters): .mm(Millimeters): .Q(Quarter-millimeters): .pc(Picas): .pt(Points): .
Font-Relative Units:
em: Relative to element font size.rem: Relative to root (<html>) font size (default ).ex/rex: Relative to font x-height (element / root).ch/rch: Relative to width of character"0"(zero).cap/rcap: Relative to height of capital letters.lh/rlh: Relative to line height.
Viewport-Relative Units:
vw/vh: of viewport width / height.vmin/vmax: of smaller / larger viewport dimension.
Container-Relative Units:
cqw/cqh: of container width / height.cqmin/cqmax: of smaller / larger container dimension.
Flexbox Layout

Overview: A 1D layout model for distributing space and aligning items along a single axis (
display: flex).Axes:
Main Axis: Primary direction determined by
flex-direction(default horizontal).Cross Axis: Axis running perpendicular to the main axis.
Key Properties:
flex-direction:row,row-reverse,column,column-reverse.justify-content: Aligns items along main axis (flex-start,flex-end,center,space-between,space-around,space-evenly).align-items: Aligns items along cross axis (flex-start,flex-end,center,stretch,baseline).flex-wrap: Controls line wrapping (nowrapdefault,wrap).
Grid Layout

Overview: A 2D layout system managing rows and columns simultaneously (
display: grid).Core Components:
Grid Lines: Numbered horizontal and vertical dividing lines starting at index .
Grid Tracks: Space between two adjacent grid lines (rows or columns).
Grid Cell: The single intersection unit of a row and column track.
Grid Area: Group of contiguous grid cells spanning multiple tracks.
Grid Gap: Gutter spacing between tracks where content cannot be directly placed.
Positioning & Z-Index
Positioning Types:
static: Default normal document flow; ignores offset properties.relative: Remains in document flow, offset relative to its original position.absolute: Removed from flow; positioned relative to nearest non-static ancestor.fixed: Removed from flow; positioned relative to viewport, staying fixed during scroll.sticky: Acts asrelativeuntil reaching a scroll threshold, then acts asfixed.
Z-Index & Stacking:
z-indexProperty: Sets depth alignment along Z-axis using positive or negative integers.Source Order Default: Without
z-index, elements defined later in document source stack above earlier ones.Stacking Context: Formed by positioned elements with specified
z-index. Child elements stack exclusively within their parent's stacking context.
Media Queries
Purpose: Applies CSS rules conditionally based on device capabilities and viewport attributes.
Syntax:
@media [not|only] mediatype and (mediafeature) { ... }Media Types:
all(default),print,screen.Media Features:
width,height,orientation(portrait/landscape),aspect-ratio.