Complete CSS Codes Guide
1. Basic CSS Syntax
selector {
property: value;
}
2. CSS Selectors
/* Universal Selector */
* { margin: 0; padding: 0; }
/* Element Selector */
p { color: red; }
/* Class Selector */
.myClass { font-size: 16px; }
/* ID Selector */
#myId { background-color: yellow; }
/* Grouping Selector */
h1, h2, h3 { font-family: Arial; }
3. Colors and Backgrounds
body {
background-color: lightblue;
color: #333;
background-image: url('[Link]');
background-size: cover;
background-repeat: no-repeat;
}
4. Text and Fonts
h1 {
font-family: 'Poppins', sans-serif;
font-size: 36px;
font-weight: bold;
color: darkblue;
text-align: center;
text-transform: uppercase;
text-shadow: 2px 2px 5px gray;
}
5. Box Model
div {
width: 300px;
padding: 20px;
border: 2px solid black;
margin: 10px;
box-sizing: border-box;
}
6. Borders and Outlines
p {
border: 2px dashed red;
border-radius: 10px;
outline: 2px solid blue;
}
7. CSS Display and Position
div {
display: block;
position: relative;
top: 10px;
left: 20px;
}
.fixed {
position: fixed;
bottom: 0;
right: 0;
}
.absolute {
position: absolute;
top: 50px;
left: 100px;
}
8. Flexbox
.container {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
.item {
flex: 1;
padding: 10px;
}
9. CSS Grid
.grid-container {
display: grid;
grid-template-columns: auto auto auto;
gap: 10px;
}
.grid-item {
background-color: lightcoral;
padding: 20px;
text-align: center;
}
10. CSS Transitions
.btn {
background-color: blue;
color: white;
transition: background-color 0.5s, transform 0.3s;
}
.btn:hover {
background-color: darkblue;
transform: scale(1.1);
}
11. CSS Animations
@keyframes slide {
from { transform: translateX(0); }
to { transform: translateX(100px); }
}
.box {
width: 100px;
height: 100px;
background: red;
animation: slide 2s infinite alternate;
}
12. CSS Pseudo-Classes and Pseudo-Elements
a:hover { color: red; }
p::first-letter { font-size: 30px; color: blue; }
13. Responsive Design (Media Queries)
@media (max-width: 600px) {
body {
background-color: lightgray;
}
h1 {
font-size: 20px;
}
}
14. CSS Variables
:root {
--main-color: teal;
--text-color: white;
}
body {
background-color: var(--main-color);
color: var(--text-color);
}
15. CSS Shadows and Effects
div {
box-shadow: 4px 4px 10px gray;
text-shadow: 2px 2px 5px black;
}
16. CSS Overflow
div {
width: 200px;
height: 100px;
overflow: auto;
}
17. CSS Z-Index
.box1 { position: relative; z-index: 1; }
.box2 { position: absolute; z-index: 2; }
18. CSS Clip Path
.circle {
clip-path: circle(50%);
background: pink;
width: 200px;
height: 200px;
}
19. CSS Gradients
div {
background: linear-gradient(to right, red, yellow);
}
20. CSS Transform
div {
transform: rotate(20deg) scale(1.2) translateX(30px);
}