๐งฑ Semantic HTML
Semantic tags describe what content is, not just how it looks โ <nav>, <header>, <main>, <article>, <button> โ instead of a page built entirely out of generic <div>s.
Every web page is built from two layers working together: HTML describes what the content is, and CSS describes how it looks. Getting the box model right underneath both saves hours of later confusion.
Semantic tags describe what content is, not just how it looks โ <nav>, <header>, <main>, <article>, <button> โ instead of a page built entirely out of generic <div>s.
CSS rules can target elements by tag, class, or ID, and more than one rule can match the same element. When rules conflict, specificity decides which one wins: an ID beats a class, a class beats a bare tag, and !important overrides almost everything (and should be used rarely).
!important to "win" a style fight instead of fixing the actual specificity or source-order conflict โ it tends to spread, since the next override needs !important too.Every element is a box made of content, padding (space inside the border), border, and margin (space outside the border). box-sizing: border-box makes width include padding and border, which is almost always what you actually want.
With content-box, padding and border add to the width; with border-box they fit inside it.
Problem: A div has width: 300px; padding: 20px; border: 5px solid. How wide is it on screen with content-box and with border-box?
Answer: 350px with content-box; 300px with border-box.
Using a real <button> instead of a styled <div onclick=...> mainly gains:
Given "p { color: black; }" and ".lead { color: blue; }" on the same <p class="lead">, the text will be:
An element matches both "#intro { color: red; }" and ".lead { color: blue; }". The color shown will be:
Relying heavily on !important to resolve style conflicts tends to cause:
With box-sizing: border-box and width: 200px, padding: 20px, border: 5px solid, the element's total rendered width is:
Without box-sizing: border-box, setting width: 200px with 20px padding and a 5px border results in a rendered width of:
A box has content width 150px, 10px padding on each side, and a 5px border on each side, using the default (content-box) box-sizing.
What is the total rendered width in pixels?
Enter a whole number.A page has 4 CSS rules targeting the same paragraph: 1 by tag, 1 by class, 1 by ID, and 1 inline style.
Ignoring !important, which single one of these 4 wins (count it as rule number 4, the inline style, being the most specific)?
Enter a whole number.Semantic HTML tags describe:
An ID selector, compared to a class selector, has:
box-sizing: border-box makes an element's width include:
Margin, in the box model, is:
Overusing !important tends to: