CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

CSS Overview


CSS, or Cascading Style Sheets, is a stylesheet language used to describe the presentation of a document written in HTML or XML. It dictates how HTML elements are displayed on screen, paper, or in other media, making web pages visually appealing.


Why use CSS? (Separation of concerns, design, responsiveness)

CSS promotes the "separation of concerns" by separating content (HTML) from presentation (CSS), making web development more organized and maintainable. It empowers designers to control layout, colors, and fonts, and is crucial for creating responsive web designs that adapt to various screen sizes and devices.

Example 1: Basic CSS Styling

/* Selects the body element */
body {
  /* Sets the background color of the entire page */
  background-color: #f0f0f0;
  /* Sets the default font family for the page */
  font-family: Arial, sans-serif;
  /* Centers the text within the body */
  text-align: center;
}

/* Selects all h1 headings */
h1 {
  /* Sets the color of the heading text */
  color: #336699;
  /* Adds a bottom margin for spacing */
  margin-bottom: 20px;
}

/* Selects all paragraph elements */
p {
  /* Sets the font size for paragraphs */
  font-size: 16px;
  /* Sets the line height for readability */
  line-height: 1.5;
}

Explanation

This CSS code demonstrates basic styling for a webpage. It sets a light gray background and Arial font for the entire document, styles h1 headings with a specific color and margin, and defines font size and line height for paragraphs, enhancing readability.


The Role of the W3C and CSS Specifications

The World Wide Web Consortium (W3C) is the main international standards organization for the World Wide Web. It develops CSS specifications, which are technical documents that define the syntax and behavior of CSS, ensuring interoperability and consistency across different browsers.


How CSS Evolves: Modules and Snapshots (CSS Snapshot 2023/2024 as reference)

CSS evolves through modules, which are self-contained specifications for specific features (e.g., Flexbox, Grid). The W3C periodically releases "snapshots," like CSS Snapshot 2023/2024, which consolidate stable modules into a single, comprehensive reference, providing developers with a clear overview of the current state of CSS.

Example 2: CSS Modules (Flexbox)

/* Selects the container element */
.container {
  /* Enables Flexbox layout for its children */
  display: flex;
  /* Distributes space evenly between and around items */
  justify-content: space-around;
  /* Aligns items vertically in the center */
  align-items: center;
  /* Sets a minimum height for the container */
  min-height: 150px;
  /* Adds a border for visual clarity */
  border: 1px solid #ccc;
}

/* Selects individual item elements within the container */
.item {
  /* Sets a background color for the items */
  background-color: #99ccff;
  /* Adds padding inside the items */
  padding: 20px;
  /* Sets a margin around the items */
  margin: 10px;
  /* Sets a fixed width for the items */
  width: 80px;
  /* Centers the text within the items */
  text-align: center;
}

Explanation

This code showcases a CSS module, Flexbox, for flexible layout. The container is set to display: flex, allowing its item children to be arranged dynamically. justify-content and align-items control the distribution and alignment of items, making responsive layouts easier to achieve.