CSS Cheat Sheet
Text & Font
p {
color: red;
font-size: 18px;
font-weight: bold;
font-style: italic;
text-align: center;
text-decoration: underline;
text-transform: uppercase;
line-height: 1.5;
letter-spacing: 2px;
word-spacing: 10px;
}
Background
div {
background-color: lightblue;
background-image: url('bg.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
background-attachment: fixed;
}
Box Model
div {
margin: 20px;
padding: 15px;
border: 2px solid black;
width: 200px;
height: 100px;
box-sizing: border-box;
}
Border & Outline
div {
border: 3px dashed red;
border-radius: 10px;
outline: 2px solid blue;
outline-offset: 5px;
}
Display & Positioning
div {
display: block;
position: relative;
top: 10px; left: 20px;
float: right;
clear: both;
z-index: 10;
}
Flexbox
.container {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
Grid
.container {
display: grid;
grid-template-columns: 200px 1fr 2fr;
grid-template-rows: auto auto;
gap: 10px;
}
Transitions & Animations
div {
transition: all 0.5s ease;
}
div:hover {
background-color: yellow;
}
@keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
div {
animation: example 2s infinite alternate;
}
Transform
div {
transform: rotate(45deg);
transform: scale(1.5);
}
Others
div {
opacity: 0.8;
cursor: pointer;
overflow: hidden;
visibility: visible;
clip-path: circle(50%);
filter: blur(5px);
}