HTML, CSS & JS, lesson 5
HTML says what things are. CSS (Cascading Style Sheets) says how they look. A CSS file is a list of rules. Each rule has a selector that picks elements, and declarations that set properties:
p selects every <p> (a type selector)..card selects every element with class="card". Classes are reusable labels you add in
HTML; an element can have several: class="card featured".#total selects the one element with id="total"..card h2 selects <h2> elements a (a selector).One exercise to try what you just read.
.cardWhen two rules set the same property, the more specific selector wins (id beats class beats type), and if they're equal, the one written later wins. That's the "cascading" part.
Every element is a box. From inside out:
Add box-sizing: border-box and width includes padding and border, which is much easier to
reason about.
Colors can be names (tomato), hex (#ff6347) or functions like rgb(255 99 71). Sizes use
px, or rem (relative to the root font size), which respects people's font settings.
Write CSS (in the style.css tab) so that:
h1 has the color rgb(180, 83, 9).card has 16px padding on all sides..card has a solid border that is 2px wide.price is bold (font-weight: 700).Don't change the HTML.
h1 {
color: #b45309;
font-size: 2.5rem;
}.card {
padding: 16px;
border: 1px solid #ddd;
border-radius: 12px;
margin-bottom: 24px;
}