All Cheat Sheets
CSS3
CSS Cheat Sheet
Selectors
Element selectorTargets all elements of a typep {
color: red;
}Class selectorTargets elements with a class.my-class {
font-size: 16px;
}ID selectorTargets a single element by ID#my-id {
background: blue;
}DescendantTargets nested elementsdiv p {
margin: 0;
}Pseudo-classTargets special statesa:hover {
color: orange;
}Box Model
ContentThe inner content areaPaddingSpace inside the borderpadding: 10px;
padding: 10px 20px;BorderEdge around paddingborder: 1px solid black;
border-radius: 8px;MarginSpace outside the bordermargin: 10px auto;
margin-top: 20px;Box sizingInclude padding and border in widthbox-sizing: border-box;Layout
DisplayControls element display typedisplay: block;
display: flex;
display: grid;
display: none;FlexboxOne-dimensional layoutdisplay: flex;
justify-content: center;
align-items: center;
gap: 16px;GridTwo-dimensional layoutdisplay: grid;
grid-template-columns: repeat(3, 1fr);
gap: 20px;PositionPositioning methodposition: absolute;
position: relative;
position: fixed;
top: 0; left: 0;