w3schools Css Complete Notes
w3schools Css Complete Notes
W3Schools
CSS
Complete
Notes
Comprehensive CSS Tutorial
from Basic to Advanced
Source: w3schools.com
Table of
Contents
1. CSS Introduction
2. CSS Syntax
3. CSS Selectors
5. CSS Flexbox
7. Responsive Design
8. Advanced Topics
9. CSS Reference
1. CSS
Introduction
What is CSS?
Sheets
in other media
CSS files
screen sizes.
CSS Example:
body {
background-color:
lightblue;
}
h1 {
color: white;
text-align: center;
}
p {
font-family:
verdana;
font-size: 20px;
}
2. CSS Syntax
A CSS rule consists of a selector
selector {
property: value;
property: value;
}
Selector
want to style
Declaration Block
separated by semicolons
Example:
p {
color: red;
text-align: center;
}
Example Explained:
<p>)
value
3. CSS Selectors
CSS selectors are used to "find" (or
want to style.
Selectors:
class)
4. Pseudo-elements selectors
element)
attribute value)
Example:
p {
text-align: center;
color: red;
}
within a page!
with a number!
Example:
#para1 {
text-align: center;
color: red;
}
with a number!
class="center":
.center {
text-align: center;
color: red;
}
with class="center":
p.center {
text-align: center;
color: red;
}
<p class="center
large">This paragraph
refers to two classes.
</p>
Example:
* {
text-align: center;
color: blue;
}
Example:
h1, h2, p {
text-align: center;
color: red;
}
Selector Example
#id #firstna
.class .intro
* *
element p
element,element div, p
4. CSS Box
Model
appear
is transparent
transparent
div {
width: 300px;
border: 15px solid
green;
padding: 50px;
margin: 20px;
}
borders.
Example:
div {
width: 320px;
height: 50px;
padding: 10px;
border: 5px solid
gray;
margin: 0;
}
Formulas to Remember:
5. CSS Flexbox
What is CSS Flexbox?
columns
float or positioning
Flex Container
Flex Items
<div class="flex-
container">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
.flex-container {
display: flex;
}
Modes:
webpage
table data
position of an element
Color Names
color: red;
HEX Values
color: #ff0000;
RGB Values
color: rgb(255,0,0);
Background Properties
body {
background-color:
lightblue;
}
.highlight {
background-color:
#ffff00;
}
.transparent {
background-color:
rgba(255, 0, 0, 0.5);
}
CSS Gradients
7. Responsive
Design & Media
Queries
Design?
Media Queries
true.
/* Small devices
(portrait tablets and
large phones, 600px
and up) */
@media only screen and
(min-width: 600px)
{...}
/* Medium devices
(landscape tablets,
768px and up) */
@media only screen and
(min-width: 768px)
{...}
/* Large devices
(laptops/desktops,
992px and up) */
@media only screen and
(min-width: 992px)
{...}
<meta name="viewport"
content="width=device-
width, initial-
scale=1.0">
8. Advanced
CSS Topics
.grid-container {
display: grid;
grid-template-
columns: auto auto
auto;
}
CSS Animations
JavaScript.
@keyframes slide-in {
from { left: -100%; }
to { left: 0%; }
}
CSS Variables
:root {
--main-color:
#007acc;
}
.header {
color: var(--main-
color);
}
CSS Specificity
9. CSS Quick
Reference
Text Properties
Layout Properties
Background Properties
background-color - Background
color
background-image - Background
image
background-repeat - Image
repeat
background-position - Image
position
Flexbox Properties
Animation Properties
animation-delay - Animation
delay
animation-iteration-count -
Repeat count
10. Practical
Examples
Example 1: Centered
Card Layout
/* CSS */
.card-container {
display: flex;
justify-content:
center;
align-items:
center;
min-height: 100vh;
background-color:
#f0f0f0;
}
.card {
background: white;
padding: 2rem;
border-radius:
8px;
box-shadow: 0 4px
6px rgba(0, 0, 0,
0.1);
max-width: 400px;
text-align:
center;
}
.card h3 {
color: #333;
margin-bottom:
1rem;
}
.card button {
background-color:
#007acc;
color: white;
border: none;
padding: 0.5rem
1rem;
border-radius:
4px;
cursor: pointer;
}
Example 2: Responsive
Navigation
/* CSS */
.navbar {
display: flex;
justify-content:
space-between;
align-items:
center;
padding: 1rem
2rem;
background-color:
#333;
color: white;
}
.nav-brand {
font-size: 1.5rem;
font-weight: bold;
}
.nav-menu {
display: flex;
list-style: none;
margin: 0;
padding: 0; Made with Genspark
}
.nav-menu li {
margin-left: 2rem;
}
.nav-menu a {
color: white;
text-decoration:
none;
transition: color
0.3s;
}
.nav-menu a:hover {
color: #007acc;
}
/* Mobile Responsive
*/
@media screen and
(max-width: 768px) {
.navbar {
flex-direction:
column;
}
.nav-menu {
margin-top:
1rem;
}
.nav-menu li {
margin: 0 1rem;
}
}
Layout
/* CSS */
.grid-container {
display: grid;
grid-template-
areas:
"header header"
"sidebar main"
"footer footer";
grid-template-
columns: 200px 1fr;
grid-template-
rows: auto 1fr auto;
min-height: 100vh;
gap: 10px;
}
.grid-item {
padding: 1rem;
background-color:
#f0f0f0;
border: 1px solid
#ddd;
}
.header { grid-area:
header; background-
color: #007acc;
color: white; }
.sidebar { grid-
area: sidebar;
background-color:
#e9ecef; }
.main { grid-area:
main; background-
color: white; }
.footer { grid-area:
footer; background-
color: #6c757d;
color: white; }
/* Responsive */
@media screen and
(max-width: 768px) {
.grid-container {
grid-template-
areas:
"header"
"main"
"sidebar"
"footer";
grid-template-
columns: 1fr;
}
}
Learning
Resources & Next
Steps
Practice Platforms
Advanced Topics to
Explore
• CSS-in-JS solutions