CSS Cheat Sheet
Basics
Basic Selectors
Selector example | Description |
---|---|
* | all elements |
.my-class | elements with class my-class |
#my-id | elemens with id my-id |
div | all <div> elements |
Combinators
Selector example | Description |
---|---|
div, p | all <div> and <p> elements |
div p | all <p> elements that are descendants of <div> |
div > p | all p elements that are direct descendants of <div> |
div + p | all <p> elements that a next sibling of <div> |
div.my-class:hover | all div elements with class my-class and pseudo-class hover |
Attribute Selectors
Selector example | Description |
---|---|
[attr] | element with attribute attr |
[attr=value] | element with attribute attr whose value value |
[attr^=value] | element with attribute attr whose value starts with value |
… |
Pseudo-classes
Selector example | Description |
---|---|
:hover | element over which a mouse cursor hovers |
:focus | element with focus |
:disabled | disabled element (e.g. <input> ) |
:visited | visited hyperlink |
:target | element that matches fragment part of current URL |
:first-child | element which is the first child of its parent |
:nth-child(3n+2) | every third child element of a parent, starting with the second child (i.e. child 2, 5, 8, …) |
:not(selector) | elements which do not match selector |
… |
Pseudo-classes
Selector example | Description |
---|---|
::before | a virtual firts child of the selected element |
::after | a virtual last child of the selected element |
::first-line | first line of text content of an element |
::selection | the portion of a document that has been highlighted by the user |
… |
CSS properties
Text styling
Useful CSS properties:
- color, font-family, text-decoration, font-weight, font-style, font-size
- text-align, line-height, text-indent
- background-color, bacgkround-image, background-repeat
- content
- …
Box model
Useful CSS properties:
- width, height, max-width, min-width, …
- padding, padding-top, …
- border, border-top, …
- margin, margin-top, …
- overflow, border-collapse, …