Web 002: Basics of CSS
This will help you:
Use CSS (Cascading Style Sheets) to define the formatting and appearance of your web content.
If you've seen websites that load in plain HTML format, you know they don't look very appetizing. CSS helps fix that by defining the appearance (color, size, font, border, background, position...) of different HTML elements. If HTML is like the nouns of a website, then CSS would be the adjectives. CSS isn't a programming language either, so don't worry...you're not learning 3 programming languages right now. ;)
Time: 1 hour / Level: A2
You should already:
Complete the Intro to HTML activity, or have a working knowledge of how to format text with HTML tags
Get the code and resources for this activity by clicking below. It will allow you to download the files from a Google Drive folder. Unzip the folder and save it in a sensible location.
Step 1: Learn About CSS
Click on this link to see an example of how much CSS can change in a website.
CSS can be written in-tag, like this:
<p color:Purple>Some text here</p>
That would show "Some text here" in purple.
It can also be written in-document, as in, standard CSS syntax inside a <style>
tag, inside the <head>
tag of the HTML document.
What is standard CSS syntax, you may ask? It's like this:
body {
background-color: yellow;
margin: 10px;
}
h1 {
color: yellow;
background-color: blue;
text-align: center;
}
p {
font-size: 15px;
}
Each of those sections in curly brackets {}
defines formatting for a certain type of tag. In this case, we defined special formatting for the body tag (all page content), top-level headings, and regular paragraphs of text.
What about tags (or format properties) that we don't define? They default to whatever the browser default is. In-tag CSS overrides document CSS and imported CSS, which overrides browser defaults.
In-tag is quick but can get repetitive and messy. In-document is better; you'd just put something like the above in a <style>
tag. The cleanest and most flexible option is to have a separate file for CSS. This is what I've done for this activity, in my_css.css
. You can open it up and take a look at it.
To tell the HTML document to use a certain stylesheet, you add a link inside the <head>
tag of the document:
<head>
<link rel="stylesheet" href="my_css.css">
</head>