Learn CSS - Syntax and Selectors Cheatsheet - Codecademy
Learn CSS - Syntax and Selectors Cheatsheet - Codecademy
Learn CSS - Syntax and Selectors Cheatsheet - Codecademy
CSS classes can be reusable and applied to many /* Selects all elements with
elements. Class selectors are denoted with a period .
class="column" */
followed by the class name. CSS ID selectors should be
unique and used to style only a single element. ID .column {
selectors are denoted with a hash sign # followed by the }
id name.
Selector Chaining
CSS selectors can be chained so that rule sets apply only /* Select h3 elements with the section-
to elements that match all criteria. For instance, to select
heading class */
<h3> elements that also have the section-
heading class, the selector h3.section- h3.section-heading {
heading can be used. color: blue;
}
CSS type selectors are used to match all elements of a /* Selects all <p> tags */
given type or tag name. Unlike for HTML syntax, we do not
p {
include the angle brackets when using type selectors for
tag names. When using type selectors, elements are }
matched regardless of their nesting level in the HTML.
Some HTML attributes can have multiple attribute values. <div class="value1 value2 value3"></div>
Multiple attribute values are separated by a space
between each attribute.
Selector Specificity
CSS ID selectors
The <link> element is used to link HTML documents <!-- How to link an external stylesheet
to external resources like CSS files. It commonly uses:
with href, rel, and type attributes -->
href attribute to specify the URL to the
external resource
rel attribute to specify the relationship of the <link
linked document to the current document
href="./path/to/stylesheet/style.css"
type attribute to define the type of content
being linked
rel="stylesheet" type="text/css">
Purpose of CSS
Inline Styles
CSS styles can be directly added to HTML elements by <h2 style="text-align: center;">Centered
using the style attribute in the element’s opening tag.
text</h2>
Each style declaration is ended with a semicolon. Styles
added in this manner are known as inline styles.
<p style="color: blue; font-size:
18px;">Blue, 18-point text</p>
Separating HTML code from CSS code
Print Share