CHAPTER 5CSS
CSS is a language specifying the style of pages. HTML is just for "abstract content", CSS decides how that content is shown. Content and style separation is a good specialization since designers can be mainly responsible for CSS and programmers or content managers for HTML.
Styling HTML
-
Using a
<link>
:<link rel="stylesheet" href="styles.css" />
-
Setting inline styles:
<div style="background-color: red">I'm so, so hot!</div>
-
Importing styles from another CSS file:
/* in styles.css... */ @import url(more-styles.css);
CSS Syntax
A CSS file is just a list of rules. Each rule has a selector, a property, and a value. Whitespace is not important, and comments are like C region comments (/*
and */
). It is important to use a formatter such as Prettier.
Rules can be grouped with braces ({
and }
) so that they share the selector, but they are independent rules anyway. The following is a piece of CSS showing two rules applying to all paragraphs:
p {
color: #222;
margin: 1rem 0;
}