@Sarah
2015-12-25T23:03:39.000000Z
字数 13233
阅读 1525
HTML
Before we ask you to write a bunch of code, we think it's helpful for you to see exactly what you'll be making in this project.
Check out the index.html file and the Result tab for an example—we've made our very own webpage.
Instructions
Hit Save & Submit Code to start building your own!
<!DOCTYPE html>
<html>
<head>
<title>Result</title>
</head>
<body><h1>YEAH SANDWICHES</h1>
<img src="http://bit.ly/RhrMEn" />
<p>I like eggs.</p>
<p>And ham!</p>
<p>But mostly sandwiches.</p>
</body>
</html>
An HTML page is sort of like a house: it needs a certain number of essential structures in order to work.
Just like a house, an HTML page needs a frame. In this case, your frame is made of , , , and tags.
Instructions
Your webpage is blank as the day it was born! Let's add five things:
The tag
Your < html> tags
Your < head> tags
< title> tags (with any title you like!) between your head tags
Your tags
<!DOCTYPE html>
<html>
<head>
<title> </title>
</head>
<body>
</body>
</html>
Your webpage could use an < h1> header between the body tags to let everyone know that the page is about you.
Instructions
Create an < h1> tag inside your body tags. Between your opening < h1> and closing < /h1> tags, type your name for all to see!
<!DOCTYPE html>
<html>
<head>
<title> </title>
</head>
<body>
<h1>Sarah will finish this</h1>
</body>
</html>
Great! There's only one problem: your webpage is like a house with no doors. There's no way to get in or out! We'll fix that by adding a couple of links.
Once you successfully add your links and hit Run, you've finished! Revel in the glory of your newly created webpage.
If it still looks a little basic to you, don't worry. We'll soon teach you CSS to make your webpages look sharp!
Instructions
Add at least two links to your webpage. You can turn an image or a bit of text into a link; you can even turn part of the text inside your
tags into a link!
Check out the Hint if you've forgotten how the tag works.
?
<!DOCTYPE html>
<html>
<head>
<title> </title>
</head>
<body>
<h1>Sarah will finish this</h1>
<img src="http://7xinhd.com1.z0.glb.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-11-30%20%E4%B8%8B%E5%8D%8810.03.11.png" />
<p> well hahahahhahahaha this is the first paragraph
</p>
<a href="http://www.baidu.com"><p> 把这段话变成链接了
</p>
</a>
<a href="http://www.baidu.com"><img src="http://7xinhd.com1.z0.glb.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-11-30%20%E4%B8%8B%E5%8D%8810.03.30.png" />
</a>
<p> well qqqqqqqqqqq
</html>
Let's continue learning more HTML. You've already covered a lot: how to set up and tags, how to make headings and paragraphs, and how to add images and links.
In this course, we'll take it to the next level:
a. Making ordered and unordered lists
b. Changing font size, color and type
c. Changing the background color
d. Aligning the text
Instructions
Let's get warmed up by adding a in the .
In the body, create a paragraph (using
). Write anything you like!
<!DOCTYPE html>
<html>
<head>
<title>aaaaa</title>
</head>
<body>
<p>
paragraph1
</p>
</body>
</html>
Now is a good time to quickly mention indentation—that is, the amount each line is spaced in from the margin. You'll notice that when we place tags inside of other tags, we indent them more. This really helps make your code more readable!
Check out our indentation in the editor to the right. Try to follow this indentation style when you're writing HTML so you don't get confused.
Instructions
Hit Save & Submit Code to continue.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
</body>
</html>
Good! Now let's learn how to make ordered lists. An ordered list is simply a list that is numbered, like the one below.
On line 8, we begin the ordered list with the opening tag
Instructions
On line 14, create an
<!DOCTYPE html>
<html>
<head>
<title>Lists</title>
</head>
<body>
<h1>List of my favorite things</h1>
<ol>
<li>Raindrops on roses</li>
<li>Whiskers on kittens</li>
<li>Bright copper kettles</li>
<li>Warm woolen mittens</li>
</ol>
<h2>List of things I find just OK</h2>
<ol>
<li>hhhh</li>
<li>hhhffh</li>
<li>hhwwwhh</li>
</ol>
</body>
</html>
We really think that ordered lists are excellent. Who doesn't love a bit of order? So let's do a bit more practice. If you forget what an ordered list looks like, feel free to look back at the previous section!
Instructions
In the body tag, create an
html
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h3>Most annoying TV celebrities</h3>
<ol>
<li> </li>fff
<li> </li>dddd
<li> </li>wwww
</ol>
<h2>Top three things I can do for Mother's Day</h2>
<ol>
<li> </li>eee
<li> </li>rrr
<li> </li>fff
</ol>
</body>
</html>
We just learned how to make ordered lists, but what if the order doesn't matter, what if we just want bullet points?
html
<h2>Taco Ingredients</h2>
<ul>
<li>Cheese</li>
<li>Sour Cream</li>
</ul>
Does this look familiar?
First, we open our list with an unordered list
So you've made ordered lists and unordered lists. Top work!
What if you have an ordered list, but each item in the ordered list also has an unordered list nested in it? Nested simply means 'inside' the list. The editor has a small example of this. Hit save & submit to see what the result looks like!
Remember: you've been nesting tags already. When you nest tags, the last tag you open is the first one you close. Here's an example:
Instructions
On line 21, create an unordered list.
Your unordered list should have two items: "Favorite Boys' Names" and "Favorite Girls' Names."
Under each item of the unordered list, create an ordered list. Use the ordered list to specify your three favorite boys' names and three favorite girls' names. Use the sample nested lists above as examples of how to do this.
<!DOCTYPE html>
<html>
<head>
<title>Nested lists</title>
</head>
<body>
<ol>
<li>Dad's interests
<ul>
<li>football</li>
<li>knitting</li>
</ul>
</li>
<li>Mom's interests
<ul>
<li>hating football</li>
<li>skydiving</li>
</ul>
</li>
</ol>
<ul>
<li>Favorite Boys' Names</li>
<ol>
<li>www</li>
<li>eee</li>
<li>rrr</li>
</ol>
<li>Favorite Girls' Names</li>
<ol>
<li>ttt</li>
<li>ggg</li>
<li>www</li>
</ol>
</ul>
</body>
</html>
We have covered a lot about lists. Let's change gears and do some styling. If you recall, HTML is the skeleton of the webpage, and CSS lets you give the skeleton some skin and makeup.
But it is possible to do some inline CSS. This simply means we can do some styling in our HTML file without worrying about a separate CSS file! We'll learn this first because it will make learning CSS a lot easier later.
Before we dive into fonts, it's important to learn about making comments. You can include little notes in your HTML code that the browser won't display. But it will be in the code to help you remember why you did certain things.
Instructions
Comments start with like this:
Make the text on line 1 into a comment. Leave the text on line 3 alone!
<!--Make me into a comment.-->
<p>But leave me visible to the user!</p>
<!-- comment -->
Recall that
and
are opening and closing tags.We can give tags more instructions by including attributes in the opening tag. An attribute is simply a characteristic or some description for the content in the element. You saw this with src in and href in .
Let's change the size of the text. How? We use the style attribute. We make it equal to font-size, followed by a colon, the size you want, and end it with px (short for "pixels"). For example:
Instructions On line 7, make the text size 10px. On line 8, make the text size 20px. On line 9, make the text size 40px. If you're having trouble with font sizes, reset your browser's zoom by pressing Cmd-0 or Ctrl-0.
<!DOCTYPE html>
<html>
<head>
<title>First font size change</title>
</head>
<body>
<p style="font-size: 10px">Some text for you to make tiny! </p>
<p style="font-size: 20px"> Some text for you to make normal size!</p>
<p style="font-size: 40px"> Some text for you to make super big!</p>
</body>
</html>
What is awesome about the style attribute is that we use it a lot! And we can use it with many different tags, not just
. Let's now change the colors of our text in a heading.
To change the color of text, simply add the style attribute in the opening tag, then make the style equal to "color:blue" (or whatever color you like). For example:
<!DOCTYPE html>
<html>
<head>
<title>Changing the colors!</title>
</head>
<body>
<h1 style="color:green; font-size:16px">Big Heading</h1>
<p style="color:violet">A giant bear and a little duck were friends.</p>
<p style="color:red; font-size:10px">But the bear got hungry and ate the duck.</p>
</body>
</html>
<h2 style="color: green; font-size:12px">
We've covered font colors and font sizes. But we want more power! We want to decide what font type to use. We can do this using font-family, like this:
First we wrote
We can do the same for other tags. So we could have a li:
Instructions
Change the font size of the first listed item (
<!DOCTYPE html>
<html>
<head>
<title>Loving the font changes</title>
</head>
<body>
<h1 style="font-family: Arial">Big title</h1>
<ol>
<li style="font-family:Arial; font-size:16px">This item is big Arial.</li>
<li style="font-family:Verdana; font-size:12px">This item is medium Verdana.</li>
<li style="font-family:Impact; font-size:10px">This item is small Impact.</li>
</ol>
</body>
</html>
<h1 style="font-family: Arial">Title</h1>
Awesome job! You've now got control of your webpage, including the color, size and type of your font. To recap, we use the style attribute in the opening tag, like so:
a. font-size: 14px
b. color: orange
c. font-family: Bodoni
<p style = "font-size:14px; color: orange; font-family: Bodoni">
It's important to know that you can use the style attribute for paragraphs, headings, and even links!
Instructions
For the paragraph on line 7, make the font have:
a. A size of 20px
b. A color of blue
c. A font-family of Arial
<!DOCTYPE html>
<html>
<head>
<title>Putting it all together</title>
</head>
<body>
<p style = "font-size:20px;color:blue;font-family:Arial">A truly spectacular paragraph!</p>
</body>
</html>
The previous section covered a number of nice tricks to control how the text looks. Now we want to learn about how to change the color of the webpage's background.
We can use the style attribute again, and set it equal to "background-color: red" (or whatever color you want).
For example, here's how to change the background color of a
tag to red:
<p style="background-color: red;">Hello!</p>
Instructions
Change the background color of the tag to brown. To do so, add the style attribute to the opening tag, similar to the example above.
Change the background color of the
<!DOCTYPE html>
<html>
<head>
<title>Sexy background color!</title>
</head>
<body style="background-color:brown">
<h3>Favorite Football Teams</h3>
<ol style="background-color:yellow">
<li>The Hawthorn Football Club</li>
<li>San Franscisco 49ers</li>
<li>Barcelona FC</li>
</ol>
</body>
</html>
Often it is nice to be able to move the text around. To do so, we again use the style attribute. And then we use "text-align:left" (or right, or center) to determine the location of the text.
<!DOCTYPE html>
<html>
<head>
<title>Sexy background color!</title>
</head>
<body>
<h3 style="text-align:center">Favorite Football Teams</h3>
<ol>
<li style="text-align:left">The Hawthorn Football Club</li>
<li style="text-align:center">San Franscisco 49ers</li>
<li style="text-align:right">Barcelona FC</li>
</ol>
</body>
</html>
We can change the appearance of words. What if we want to make them bold?
Surprise! We don't have to use the style attribute. Here are the steps:
Identify the word or words you want to bold.
Surround those words with opening tag and closing tag .
Celebrate how awesome you are at HTML!
Instructions
Bold the word 'sing' on line 7.
Bold the word 'too' on line 8.
?
<!DOCTYPE html>
<html>
<head>
<title>Viva La Revolution!</title>
</head>
<body>
<p>Do you hear the people <strong>sing</strong>?</p>
<p>No I don't. I'm <strong>too</strong> busy eating cake.</p>
</body>
</html>
Aside from bolding words, we often want to italicize words for emphasis. (Hint, hint.)
Like bolding, we do not need to use the style attribute. Instead:
Identify the word or words you want to italicize.
Surround the word or words with the opening tag and closing tag .
Be humble and grateful for your newfound powers.
Instructions
On line 7, italicize the word 'that'.
On line 8, italicize the word 'so'.
Make sure you don't include the "!" between the tags on line 7!
<!DOCTYPE html>
<html>
<head>
<title>Some nice practice</title>
</head>
<body>
<p>Hey, don't say <em>that</em>!</p>
<p>I am <em>so</em> tired.</p>
</body>
</html>
This has been an incredibly busy lesson, and you've covered a lot. Congratulations! We have learned how to:
Make ordered and unordered lists
Change the color, size and type of font
Add comments to our HTML file
Change the page's background color
Align text
Bold and italicize text