@Sarah
2015-12-25T19:59:12.000000Z
字数 9607
阅读 1049
HTML
Every webpage you look at is written in a language called HTML. You can think of HTML as the skeleton that gives every webpage structure. In this course, we'll use HTML to add paragraphs, headings, images and links to a webpage.
In the editor to the right, there's a tab called test.html. This is the file we'll type our HTML into. See the code with the <>s? That's HTML! Like any language, it has its own special syntax (rules for communicating).
When we press Save & Submit Code, the results tab will act like an Internet browser (e.g. Chrome, Firefox, Internet Explorer). A browser's job is to transform the code in test.html into a recognizable webpage! It knows how to lay out the page by following the HTML syntax.
To the right, we have a test.html file.
Change the text on line 2 (the bit between and ) to anything you like!
Hit Save & Submit Code, and you'll see how the test.html file would look in a browser. Did you see that? The tags made our text bold!
?
<!DOCTYPE html>
<strong>I will finish this course today!</strong>
HTML stands for HyperText Markup Language. Hypertext means "text with links in it." Any time you click on a word that brings you to a new webpage, you've clicked on hypertext!
A markup language is a programming language used to make text do more than just sit on a page: it can turn text into images, links, tables, lists, and much more. HTML is the markup language we'll be learning.
What makes webpages pretty? That's CSS—Cascading Style Sheets. Think of it like skin and makeup that covers the bones of HTML. We'll learn HTML first, then worry about CSS in later courses.
The first thing we should do is set up the skeleton of the page.
a. Always put on the first line. This tells the browser what language it's reading (in this case, HTML).
b. Always put on the next line. This starts the HTML document.
c. Always put on the last line. This ends the HTML document.
Instructions
Go ahead and put the three lines mentioned above into test.html, which is now blank.
In between the second and last line (between the and the ), feel free to write whatever message you like.
<!DOCTYPE html>
<html>
I will finish this course today!
</html>
To learn more HTML, we should learn how to talk about HTML. Already you have seen we use <>s a lot.
Things inside <>s are called tags.
Tags nearly always come in pairs: an opening tag and a closing tag.
Example of opening tag:
Example of closing tag:
You can think of tags as being like parentheses: whenever you open one, you should close it. Tags also nest, so you should close them in the right order: the most recently opened tag should be the first one closed, like in the example below.
<first tag><second tag>Some text!</second tag></first tag>
The last exercise taught us how to set up our HTML file. Everything we do now will go between and .
Practice makes perfect! One more time:
Instructions
Put in the tag.
Put in the opening and closing tags.
Between the tags, write whatever you like.
Press Save & Submit Code to see what you've written appear on the page!
<!DOCTYPE HTML>
<html>
I must finish this course today !yay
</html>
Everything in our HTML file will go between the opening and closing tags.
There are always two parts to an HTML file: the head and the body. Let's start with the head.
The head contains information about your HTML file, like its title. The title is what we see in the browser's title bar or page tab. For example the title of this page is "HTML Basics | Codecademy".
Instructions
Let's add a head and a title to our webpage. If you get stuck at any point, click "Stuck? Get a hint!" below for an example.
Add an opening tag and closing tag.
Between the tags, add in an opening tag and closing tag.
Between the tags, write in a title for your page. For example, "My Webpage."
Press "Save & Submit Code" to continue
<html>
<head>
<title>My Webpage</title>
</head>
</html>
Great job! To review, an HTML file has both a head and a body. The head is where you put information about your HTML file, like its title.
The body is where you put your content, such as text, images, and links. The content in the body is what will be visible on the actual page.
The body goes inside the tags, right after the tags, like this:
<html>
<head>
<title>My Webpage</title>
</head>
<body>
</body>
</html>
Instructions
Underneath the closing tag, put an opening tag and a closing tag, like in the example above.
Inside the body, create two paragraphs. Each paragraph starts with an opening
tag and ends with a closing
<body>
<p>Hello world!</p>
</body>
```
My Webpage
Hello
Hello2
<div class="md-section-divider"></div>
##Paragraphs and headings
We're definitely making good progress! We've learned when and why we use HTML. We've also learned how to:
a. Set up an HTML file with tags
b. Title the webpage (in the <head>)
c. Create paragraphs (in the <body> with <p> tags)
The next step is to give our paragraphs headings using heading tags. Let's start with the <h1> tag. The content between this tag will be the biggest!
Instructions
In the body section, create a heading. To do this, create an <h1> tag Add content.
Close the element with a closing tag </h1>. (Your content should now be between <h1> and </h1>.)
Underneath the heading tags, create two paragraphs using <p> tags with whatever content you like.
<div class="md-section-divider"></div>
```html
<!DOCTYPE html>
<html>
<head>
<title>
Headings & Paragraphs
</title>
</head>
<body>
<h1>
the first heading
</h1>
<p> hhh</p>
<p>yyy</p>
</body>
</html>
HTML actually lets us have more than one heading size. There are six heading sizes, where
<!DOCTYPE html>
<html>
<head>
<title>
Headings & Paragraphs
</title>
</head>
<body>
<h1>
the first heading
</h1>
<p> p1</p>
<h3>third heading</h3>
<p>p2</p>
<h5>fifth heading</h5>
<p>p3</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>
Headings & Paragraphs
</title>
</head>
<body>
<h1>the first heading </h1>
<p> p0</p>
<h2> second heading</h2>
<p> p1</p>
<h3>third heading</h3>
<p>p2</p>
<h4>forth heading</h4>
<p> p2.5</p>
<h5>fifth heading</h5>
<p>p3</p>
<h6>sixth heading</h6>
<p> p7</p>
</body>
</html>
You've done an awesome job! Here's a quick summary of things we've learned:
HTML is used to give websites structure.
We open HTML files using a browser, and the browser renders (shows us) the file.
HTML files have a and a (just like you!)
In the head, we have the tags, and we use these to specify the webpage's name.
How to make headings and paragraphs.
Instructions
Add a title between the tags.
Create a
tags and fill them with content (e.g. about cars, your pet, favorite city to travel—whatever you like!)
What if you wanted to send the user to another part of your website, or another website altogether? You use hyperlinks, or links for short!
<a href="http://www.codecademy.com">My Favorite Site!</a>
First, there's an opening tag and that tag has an attribute called href. The href value tells your link where you want it to go, in this case http://www.codecademy.com.
Then you have a description of your link between your opening and your closing tags. This is what you will be able to click on.
Finally, you have your closing tag.
Instructions
In the body section, create a link. To do this, create an tag. Point your link to a website by setting the value of the href attribute
Add a description of your link
Close the element with a closing tag
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<a href="http://www.baidu.com">baidu!</a>
</body>
</html>
You can add images to your websites to make them look fancy.
We use an image tag, like so: . This tag is a bit different from the others. Instead of putting the content between the tags, you tell the tag where to get the picture using src. It's also different because there is no ending tag. It has / in the tag to close it: .
Check out the tag to the right—it adds a picture of a rubber duck to the page! (You can see it by clicking on the Preview button.)
See the web address (or URL) after src=? It's "https://s3.amazonaws.com/codecademy-blog/assets/f3a16fb6.jpg". That tells the tag where to get the picture from!
Every image on the web has its own image URL. Simply right-click on an image and choose "Copy image URL." Paste that URL in quotes after src= to insert with your tag.
Instructions
Add a second image below the first one. (Make sure it's before the closing tag!)
If you can't think of a good picture, use this ninja:
https://s3.amazonaws.com/codecademy-blog/assets/ninja_zpsa5dbe37a.jpg
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<img src="https://s3.amazonaws.com/codecademy-blog/assets/f3a16fb6.jpg" />
<img src="http://7xinhd.com1.z0.glb.clouddn.com/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85%A7%202015-04-18%20%E4%B8%8B%E5%8D%886.21.42.png"(这里有个空格) />
</body>
</html>
Good work! Now you know how to add links and images to your website. Why not make that image a link? For example:
<a href="http://www.codecademy.com/">
<img src="https://s3.amazonaws.com/codecademy-blog/assets/f3a16fb6.jpg"/>
</a>
First we open our tag and point the href to http://www.codecademy.com/ again.
But this time, instead of using text inside the tag, we use an tag.
Finally, we have our closing tag.
Now when you click on the yellow duck, you will be taken to http://www.codecademy.com!
Placing one HTML tag inside of another is called nesting.
Instructions
In the body section, create an tag.
Choose a website to point your link to, like .
Now create your tag between your opening tag and closing tag. Don't forget the src!
Finally, close your tag after your tag.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<img src="https://s3.amazonaws.com/codecademy-blog/assets/f3a16fb6.jpg" />
<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-04-18%20%E4%B8%8B%E5%8D%886.21.42.png" />
</a>
</body>
</html>
Good work! Let's make sure you really understand images and links before we move on to the review.
Instructions
Between the tags, add two images using the tag. One should be a link; the other should not. The link can go anywhere you want.
After your two images, create a link that's just a line of text. It can link anywhere you want.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<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>
<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.17.png" />
<a href="http://www.baidu.com">kkkkk</a>
</body>
</html>