Actually, the CSS is written in a different file. (It can be written in the HTML file, but it's considered best practice not to, as with Ottergram.) But the classes go in the HTML file to label elements.
The box model applied to both, but certain values (width, for example) are ignored for inline elements. Weird, but true. That's why inline-block was invented.
ID is an attribute, not a tag. So:
Now consider the following rules:
With the following result:
When we want a rule to apply to every element that uses
that tag. For example, every LI
or
every NAV
.
But we often want to be more specific, so we use class or (rarely) ID.
A selector chooses a set of elements to apply the rule to. An ID is just one kind of selector.
Above, there's only one Fred, but there are multiple Gryffindors.
A class is like a category or a label. It can be applied to more than one thing.
An ID should be unique.
Look at the formatting of #fred
, above.
We almost never use inches, unless we are formatting something for printing.
EM is used when we want something to adjust with the font size; often a good idea
PX is often used for narrow things, like borders and padding.
percentages are used for big things, like MAIN or SECTION, or FIGURE or IMG
EM might differ from place to place because of inheritance. If you don't want that, use REM.
So, 2em
is twice as big as an EM. Nest those, and you get 4EM.
But 2rem
will always be the same size.
This rule happens to apply to the hyperlinks that surround each picture. (You can look back at the HTML to see all the elements that are class=""thumbnail-item-a"".)
I am confused about the content after the =
Let's look back at the HTML for this: Ottergram HTML
These are confusing! Originally there was just BLOCK (big boxes) and INLINE (word-like things that go in paragraphs).
But INLINE-BLOCKS were added to create things that flow like words, but have width, containing block content.
Turns out browser have different defaults. For example, one browser might have a default margin for BODY of 8px, while others have a default of 0px.
If you want your website to look the same on all browser, you have to decide all those things, to make them consistent.
Normalize does that for you.
Personal preference. There's no requirement that a class apply to only one thing, so you can create a class and apply it to just one thing, just like with an ID.
But ID is useful in that (1) you can use them for hyperlinks, (2) it tells other programmers that something is unique, and (3) ID rules have precedence over class rules.
We'll do some practice today and over the next few weeks!