Let’s try one more analogy, just to explain how fluid HTML, CSS can be:
Think of a webpage as a play. Say, Shakespeare’s Romeo and Juliet:
The HTML is the script -- the lines the actors and actresses say as the play progresses. It’s “In Fair Verona, where we lay our scene”, it’s “What's in a name? that which we call a rose / By any other name would smell as sweet”.
The CSS is the costume and set design -- how everyone looks, and how the set looks. It’s the poofy shoulders, the cobblestone street, the oil lamps.
Two people can take the same content and style it very differently. In terms of Romeo and Juliet, you have the classic 1968 version, with swords, tunics and cobblestone streets.
And you have the 1996 version with Leonardo di Caprio, guns and suits. The two movies have the exact same lines, but they look and feel very different. That’s what CSS can do to HTML.
<html>
<head>
<title>Consider the lobster</title>
<!-- Our new CSS link: -->
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>Consider the lobster</h1>
<p>The point is that <strong>lobsters</strong> are basically
giant sea-insects.</p>
</body>
</html>
Under the title tag, we can put in a link tag. -- You'll notice the link tag doesn't have a closing tag. Tags like this are called "empty elements"; they will never contain anything, they only have attributes.
Looking at what it says: "rel" stands for relation, and "href" stands for hypertext reference (remember how HTML stands for Hyper Text Markup Language? Yeah, you'll never have to think about that fact again.) So this essentially says, the reference I'm about to give you is a stylesheet, and here it is, at css/styles.css.
Okay, let's look at some CSS.
<html>
<head>
<title>Consider the lobster</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>Consider the lobster</h1>
<p>The point is that <strong>lobsters</strong>
are basically giant sea-insects.</p>
</body>
</html>
h1 {
color: red;
}
The point is that lobsters are basically giant sea-insects.
This is called a CSS rule, and it has three parts:
So now you know what these mean, here's another way to think about it. And it's how I think about it when I'm coding.
But it doesn't have to stop with one property.
h1 {
color: red;
font-family: ‘Comic Sans MS’;
}
The point is that lobsters are basically giant sea-insects.
So this says, all H1s should be the color red and use the font ‘Comic Sans MS’.
What if we want to change how the paragraphs look? We can add another rule.
h1 {
color: red;
font-family: ‘Comic Sans MS’;
}
p {
font-size: 18px;
}
The point is that lobsters are basically giant sea-insects.
So you're starting to get the hang of reading CSS. Before we let you write your own, we wanted to show you one more thing.
Colors. What if I don't want it to be generic red? How do I tell the Internet what color I want it to be? With numbers, or more specifically, hex codes.
h1 {
color: #FF0000;
}
These aren't even all the options for red. But if you ever are stuck, there are great tools out there for picking colors, let's google it together.
Don't know how to write a CSS property? Google it!
So that’s the gist of it. We’ll let your mentors help you get some CSS on your page, and they’ll show you some more properties. When you’re feeling comfortable with that, we have an exercise for you to style your HTML page in a certain way.