Complete CSS Documentation
Complete CSS Documentation
1. Introduction to CSS
What is CSS?
CSS (Cascading Style Sheets) is a stylesheet language used to control the layout
and presentation of web pages written in HTML or XML.
It separates content from design, allowing for easier maintenance and styling.
Key Concepts
Cascading: Styles can cascade from one style sheet to another, allowing for
multiple sources of styling.
Selector: A pattern used to select the elements you want to style.
Declaration Block: Contains properties and values that apply to the selected
elements.
2. CSS Syntax
Basic Structure
selector {
property: value;
}
Comments
3. CSS Selectors
Basic Selectors
Combinators
Attribute Selectors
Pseudo-Classes
Examples:
:hover - Applies styles when the element is hovered over.
:focus - Applies styles when the element is focused.
:nth-child(n) - Selects the nth child of a parent.
Pseudo-Elements
Examples:
::before - Inserts content before an element.
::after - Inserts content after an element.
::first-letter - Styles the first letter of an element.
4. CSS Properties
Text Properties
Box Model
Background Properties
Display Properties
Positioning
float: Allows elements to be taken out of the normal document flow and
positioned to the left or right.
clear: Specifies whether an element can be next to floating elements or if it
should be moved below them.
5. Layout Techniques
Flexbox
Grid
Transitions
.box {
transition: background-color 0.5s ease;
}
.box:hover {
background-color: blue;
}
Animations
@keyframes slide {
from { transform: translateX(0); }
to { transform: translateX(100px); }
}
.animated {
animation: slide 2s infinite;
}
7. Media Queries
:root {
--main-color: #3498db;
}
body {
background-color: var(--main-color);
}
9. CSS Functions
Color Functions
rgba(): Defines a color with red, green, blue, and alpha (transparency).
hsl(): Defines a color using hue, saturation, and lightness.
var(): Used to access CSS variables.
Positioning Functions
Nested Grids: Creating grids within grids for more complex layouts.
Grid Template Areas: Using named areas for easier layout management.
Mobile-First Approach: Designing for mobile devices first and then using media
queries for larger screens.
Fluid Layouts: Using relative units like percentages and vw/vh for responsive
designs.