CSS uses selectors to target HTML elements and apply rules.
selector {
property: value;
}| Selector | What It Targets | Example |
|---|---|---|
element |
All of that HTML element | p { color: blue; } |
.class |
Elements with that class name | .button { background: pink; } |
#id |
One element with that ID | #main { padding: 20px; } |
element:hover |
Element when hovered | button:hover { transform: scale(1.1); } |
element child |
A child inside another | div p { color: gray; } |
element, element |
Multiple elements | h1, h2 { font-family: sans-serif; } |
Tip: CSS files are read top to bottom, and when rules conflict, the most specific selector wins.
Try these on body, div, or section:
background-colorbackground-imagebackground-sizecolorfont-familyfont-sizeline-heighttext-alignmarginpaddingborderborder-radiusbox-shadow
Target your button with button { ... } and button:hover { ... }.
Try:
background-colorcolorborderborder-radiuspaddingfont-weighttext-transformcursorbox-shadowtransitiontransform
Example:
button {
background-color: cornflowerblue;
color: white;
border: none;
border-radius: 8px;
padding: 10px 16px;
transition: transform 0.2s;
}
button:hover {
transform: scale(1.1);
}You can target sliders and their subparts:
input[type=range]– the overall slider::-webkit-slider-thumb– the handle::-webkit-slider-runnable-track– the line
Start simple:
input[type=range] {
accent-color: hotpink;
}Then customize:
input[type=range]::-webkit-slider-thumb {
background: black;
border-radius: 50%;
height: 20px;
width: 20px;
}Experiment with:
display(block,inline-block,flex,grid)justify-contentalign-itemsgapposition(relative,absolute,fixed)top,left,right,bottomwidth,heightmax-width,min-width
Try these for creative flair:
opacityfilter(blur(),brightness(),contrast(),hue-rotate())transform(scale(),rotate(),translate())transition(property duration easing)mix-blend-modecursor
Play around with:
box-shadowtext-shadowclip-pathbackground: linear-gradient()border-image