CSS
Key concepts:
CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of a document written in HTML or XML. Here are some key concepts in CSS:
-
Selectors:
- Element Selector: Selects all instances of an element. (
p,h1) - Class Selector: Selects elements with a specific class. (
.classname) - ID Selector: Selects a single element with a specific ID. (
#idname) - Attribute Selector: Selects elements with a specific attribute. (
[type="text"])
- Element Selector: Selects all instances of an element. (
-
Properties and Values:
- Properties define the aspects of styling (e.g., color, font-size).
- Values assign specific settings to properties (e.g.,
color: red;,font-size: 16px;). - Variables, aka custom properties, are defined by authors once and can be reused throughout.
- @property allows authors to define the syntax and initial values of variables. Useful in animations.
-
Box Model:
- Content: The actual content of the element.
- Padding: Space between the content and the border.
- Border: The border surrounding the padding (and content).
- Margin: Space outside the border.
-
Display and Positioning:
- display: Defines how an element is displayed (
block,inline,flex,grid, etc.). - position: Defines how an element is positioned (
static,relative,absolute,fixed,sticky). - z-index: Determines the stack order of elements (higher values are in front).
- display: Defines how an element is displayed (
-
Flexbox and Grid:
- Flexbox: A layout model for distributing space along a single axis. (
display: flex;) - Grid: A layout model for two-dimensional layouts. (
display: grid;)
- Flexbox: A layout model for distributing space along a single axis. (
-
Responsive Design:
- Media Queries: Apply styles based on device characteristics (e.g., width, height, orientation). (
@media screen and (max-width: 600px) { ... }) - Units: Use relative units like percentages (
%), viewport width (vw), and viewport height (vh) for responsiveness.
- Media Queries: Apply styles based on device characteristics (e.g., width, height, orientation). (
-
Color:
- Color Values: Defined using names (
red), hex codes (#ff0000), RGB (rgb(255,0,0)), or HSL (hsl(0, 100%, 50%)).
- Color Values: Defined using names (
-
Typography:
- font-family: Specifies the font of the text. (
font-family: Arial, sans-serif;) - font-size: Sets the size of the text. (
font-size: 16px;) - font-weight: Defines the weight (thickness) of the font. (
font-weight: bold;) - line-height: Sets the height of a line of text. (
line-height: 1.5;)
- font-family: Specifies the font of the text. (
-
Transitions and Animations:
- Transitions: Smooth changes between property values. (
transition: all 0.3s ease;) - Animations: More complex, keyframe-based animations. (
@keyframes anim { 0% { opacity: 0; } 100% { opacity: 1; } })
- Transitions: Smooth changes between property values. (
-
Pseudo-classes and Pseudo-elements:
- Pseudo-classes: Define special states of an element (
:hover,:active,:focus). - Pseudo-elements: Style specific parts of an element (
::before,::after).
- Pseudo-classes: Define special states of an element (