Short Notes on CSS
What is CSS?
- CSS is used to style HTML elements.
- It stands for Cascading Style Sheets.
Ways to Apply CSS
- Inline CSS: Directly inside an element (
style="color: red;"). - Internal CSS: Inside
<style>tags in<head>. - External CSS: In a separate
.cssfile and linked via<link>.
CSS Syntax:
selector {
property: value;
}
e.g;
h1 {
color: blue;
font-size: 20px;
}
CSS Selectors
Types of Selectors:
- Universal (
*) →* { margin: 0; } - Element (
h1, p) →p { color: green; } - Class (
.class-name) →.box { border: 1px solid black; } - ID (
#id-name) →#header { background: gray; } - Group (
h1, p) →h1, p { color: red; } - Descendant (
div p) →div p { font-size: 14px; } - Child (
div > p) →div > p { color: blue; } - Adjacent (
h1 + p) →h1 + p { margin-top: 10px; }
CSS Box Model
Understanding Box Model Components:
- Content → Actual text/image inside the element.
- Padding → Space around content.
- Border → Line around padding.
- Margin → Space outside the border.
Example:
CSS Positioning
Position Properties:
static(default)relative(relative to itself)absolute(relative to nearest positioned ancestor)fixed(relative to viewport)sticky(sticks to position on scroll)
Example:
CSS Flexbox (Responsive Layouts)
Key Properties:
display: flex;→ Enables Flexboxjustify-content→ Aligns items horizontallyflex-start|flex-end|center|space-between|space-around
align-items→ Aligns items verticallyflex-start|flex-end|center|stretch
flex-direction→ Controls layout directionrow|row-reverse|column|column-reverse
Example:
CSS Grid (Advanced Layouts)
Key Properties:
display: grid;→ Enables Gridgrid-template-columns→ Defines columnsgrid-template-rows→ Defines rowsgap→ Space between grid itemsgrid-area→ Name grid sections
Example:
CSS Transitions & Animations
Transitions:
Animations:
Media Queries (Responsive Design)
Make websites mobile-friendly:
Advanced Concepts
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
.png)
Comments