HTML和CSS教程

网友投稿 705 2022-11-06

HTML和CSS教程

HTML+CSS Tutorial

Who

I'm Cassidy. I'm a engineer and I've been teaching myself HTML, CSS, and other web development and scripting for over 15 years. And I want to teach you now. Because you're good looking. And because it's useful.

What

In this tutorial, we'll start from the very beginning. You don't need to know anything about HTML and CSS or anything about code to start. I'll include some tutorial files for you to play with and check out.

When

Now. Or whenever. I'm not planning on taking this down anytime soon. But you are only limited by your own schedule. Or set free by it. Whatever.

Where

On a computer. Here.

Why

Because this stuff is important. Whether you're a business person formatting your emails, an aspiring web designer wanting to get your feet wet, or just someone who is interested and hasn't tried any sort of coding, scripting, or programming before, HTML and CSS are an essential part of your learning curve.

Table of Contents

HTMLEditorsTag StructureText StructureLinksOther tags ImagesLine BreaksTables Making Things Gorgeous The Wrong Way ColorsWidth and HeightBordersText Styles The tagPutting it all together so far CSSClasses and IDs and other Segregation ClassesIDsOther Segregation The tagThe

tag Background colorFloatingPositioningMargins and PaddingZ-Index The Tag, Comments, and other Developer Joys The tagCommenting HTML CommentsCSS Comments Other Developer Joys FormsHTML5 and CSS3How To Meet Losers (Get it? HTML Jokes are the best...) Final Project!And now, the end is near

HTML Time. Let's Go.

Editors

So the first thing you'll need is an editor to edit your jazz. There's tons of options out there.

Notepad/TextEdit (that's right, the stupid thing that comes on your computer) - This is about as basic as you can get. It's totally okay if you want to use this, but I recommend one of the editors below just so you can see code highlighting (which will help you out later on). But, if you want to be a purist, this'll work just fine.Visual Studio Code - This is what I typically use. It's open source and has TONS of extensions available.Atom - This is another very customizable option, with a huge plugin library and open source so it's always being improved.Sublime Text 3 - This is a pretty popular option, and for good reason. Very clean interface. Once you can navigate it (learning curve isn't that big), it's pretty dreamy. Like your face.CodePen Projects - This is an in-browser code editor, so you can code directly within the web browser, no downloads required. :)Glitch - This is another in-browser code editor. It is meant for larger projects, but it's nice to not have to download anything!Notepad++ - This is just one step up from Notepad. But it's pretty dece. Code highlighting is in it, and nothing else too fancy, which is what I like about it.

There's a bunch of others listed here, I just listed the ones I've used and liked!

HTML Tag Structure

Here is a barebones HTML page, about as simple as you can get. You can open it up in the 1 - Structure folder in the file part1.html. If you were to open the file in your favorite browser (which you can do, go ahead), you'll see a plain webpage with the title "My Website" and the words, "Hello, World!" written on the page.

My Website Hello, World!

So, what are we looking at here? HTML, short for HyperText Markup Language, consists of these things called tags, which are words written between < and > characters, like . All tags (with just a few exceptions that we'll talk about later) have a matching closing tag, which has the same name as the opening tag, except that it contains / after the first <, like .

For example, is one tag and the closing tag for it is , same with and and and , and so on. You get it. The opening and closing tags together are an element (which also includes everything written in it). For example, My Website is one element. The text inside an element, in the title case, My Website, is called the content of an element.

Tags organize your page and tell the browser what your page consists of. There's tons of tags out there, some that you may never use. Here's some lists of tags if you really care to see all of them at this point:

HTML Dog Tag ListW3Schools Tag ListQuackit HTML Tag List

So, if you look at our example, you can also put tags inside other tags (like we did with the tags inside the <head> tags). This is called nesting elements. In this case, we would say that the <head> contains the <title>. Sometimes when you have a lot of nested tags, it's hard to keep track, so you have to format your code with spacing, as shown. Typically, inner tags are spaced more than their outer tags (just as <title> is indented further than <head>).</p><p>Let's take a look again at part1.html in the 1 - Structure folder. You'll notice that the first line has <!doctype html>. Every HTML document and website has to have this special tag, as it tells the browser what language we're using. This is one of those special tags I mentioned that doesn't need a closing tag.</p><p>On the second line, you can see a <html> tag. Everything in the website is contained by this tag, and the last line of your entire document will always be </html>.</p><p>Inside <html>, there are two elements: <head>and <body>. Contained in , we will put all kinds of information for the browser that the user doesn't necessarily need to see. For now, we just have <title>. The content of <title> will be used for the name of the tab of the browser, and also by search engines.</p><p>On the other side of the planet, we have . Everything visible to the user is contained in these tags. Right now, all that consists of is "Hello, World!" Let's change that for fun. Replace "Hello, World!" with your own text in your favorite HTML editor, and then open the page in your browser. Neat!</p><p>Structuring text</p><p>Let's get juicy. We're going to talk about some new tags for structuring your text. Because you're not going to want just one style of text throughout your whole website, right?</p><p>Check out part2.html in the 1 - Structure folder. The tags that we'll be talking about here are <h1>, <p>, <ul>, and <li>. Open the file in the browser to try and understand what the heck is going on.</p><p>Now, let's talk about it.</p><p>First, we have <h1>, which adds a heading to our website. Basically, a heading is just text with a bigger font. But still. Important. We'll soon learn how to adjust any and all font sizes, but not yet. Just know that your headings should be in <h1> tags. Also, if you have a smaller heading, or sub-heading, you could use <h2>, which is smaller than <h1>, but bigger than regular text. You can keep going with more numbers until you reach <h6>, with each heading a bit smaller than the previous. Try adding some subheadings underneath our current heading!</p><p>Next, we have <p> tags. <p> adds a paragraph of text to our website, which are blocks of text that have some space before and after them. Edit the text in the paragraphs given, and add your own to see what I mean!</p><p>And finally, we have <ul>. <ul> means a bulleted list (also known as an unordered list), where every <li> is an item in that list (called a list item). But what if you want a numbered list? You could change <ul> to <ol> (and don't forget its closing tag), it's that simple! <ol> is an ordered list, which has numbers instead of bullet points, and that is truly the only difference. Add some list items (<li>) to the list (make sure you stay inside the <ul> tags), and then change your <ul> tags to <ol>!</p><p>Links</p><p>Links are what makes the world/Internet go 'round. Seriously. So, let's learn about them.</p><p>Links are made with the <a> tag, which stands for anchor.</p><p>Open up the 2 - Tags folder, and add this piece of code right after your heading in page1.html:</p><p><p>This paragraph has a totally awesome link.</p></p><p>Open page1.html in a browser and click on it! BEAUTIFUL.</p><p>Okay, so let's take a look at this. First of all, you can see the <a> tag there contained in the paragraph. Beautiful. But what's that funky milk href=? Well, that syntax called an attribute. Attributes change the way a tag works, and are not visible to the website's user. You only add attributes to the opening tag, not a closing tag. Tags can have multiple attributes, for example:</p><p><tag attribute="value1" attribute2="value2">Content of tag</tag>`</p><p>Got it? Good. You're so good looking.</p><p>So, anyway, the attribute 'href' tells us where the link is going to go when the user clicks on it (and for those curious, it stands for hyperreference). Try adding some more links to the page to different websites!</p><p>Also, one thing you should note: Links don't have to be in <p> tags like I put above. You could put them in <li> tags in a list, <h1> tags for a linking header, or completely on their own!</p><p>Adding links to other pages in your website</p><p>Let's just say you have a fully functioning website called fakewebsite.com. You have your homepage and your "Contact Us" page in the same directory or folder.</p><p>Normally when a beginner links to different pages on their website, they just make links that look like Home and Contact Us.</p><p>This is okay. BUT, you can do better. So, what if you change your domain name to reallyfakewebsite.com? When you edit your HTML, you'd have to edit every single one of the links to match the new domain. That's gross. There is a better way.</p><p>When you make a link to a page within your own directory or folder on your website, instead of putting in the whole URL, put in something more like this:</p><p>Click here to go back to Page 2.</p><p>Paste this line of code into page1.html. Watch the magic happen.</p><p>Now, if you were to change your domain or location of your files, you don't have to change a thing. Boo yah.</p><p>Other tags</p><p>So, you can reference the links that I showed you before if you want to check out some jazzy stuff you can do with your page. There are some other ones though that you might want to see before we move on to cooler and bigger things.</p><p>Images</p><p><img>. Let's just say you want to put an image on your website. This is probably a good tag to know. Add the following to page1.html:</p><p><img src="https://i.imgur.com/B9q0A.gif" /></p><p>Open up the page in a browser. WHOA. Image! So, the <img> tag is one of those special tags. First of all, it doesn't have a closing tag. You just stick in a / at the end of the one tag and you're done. Secondly, it also has a src attribute (which is short for source), and in the value of that attribute you put the URL of the image (similar to href in the anchor tag).</p><p>One attribute that might be good for you to remember for <img> tags is the alt attribute. If you changed the code above to:</p><p><img src="https://i.imgur.com/B9q0A.gif" alt="I could have danced all night" /></p><p>When you load the page in the browser, the image looks the same. But, if you roll your mouse over the image, you'll see some words appear! WOW. That's the alt attribute. It stands for the alternate text for an image, and it's used when a user can't view the image for whatever reason (using a screen reader, slow connection, error in the src attribute, etc.). Or, in the case of XKCD, it's used to add more humor to the page (roll your mouse over all of the comics on the site, they always add another joke or two that a lot of people don't know about).</p><p>Line breaks</p><p>Let's just say you want to keep all your content in one paragraph <p>, but you still want to break it up.</p><p>That's easy.</p><p>So, there's two special tags here, <hr> and <br>. They are empty tags, meaning they have no closing tag.</p><p><hr> stands for horizontal rule, and creates a visible line break. <br> is a simple line break, all it does is split your paragraph up.</p><p>Try inserting these in between some of your <p> tags to try it out!</p><p>Tables</p><p>Tables are really cool. They can also be a bit confusing. Open up tables.html (in the 2 - Tags folder) in a browser to check out the example table I made for you there.</p><p>There's several tags for tables, but the essential ones are <table>, <tr>, <th>, and <td>. Look at tables.html in your editor.</p><p>We're going to make our own table again on this page. You can delete the one I made for you, or just make one underneath the current one there.</p><p>So, to create a table, you start with the <table> tag. Simple enough.</p><p>This will contain all the parts of your table. Sometimes, tables have a border attribute that will equal some value for the thickness of the table's border (it's proper to have just "1" or nothing, for reasons we'll explain later). Go ahead and add one so it looks like this:</p><p></p><p>Boom. Let's add some more.</p><p>The next tag we're gonna check out is <tr>, which is for a table row. Easy peasy. So, let's add 3 <tr> tags to our table.</p><p><table border="1"> </table></p><p>And finally, we have the actual cells of the table. There are two types of tags for this, <th> (table header) and <td> (table data). As their names indicate, the former is for the header of the table and the latter is for all of the data in the table.</p><p>In our first set of <tr> tags, add 4 <th> tags, and in the second and third <tr> tags add 4 <td> tags.</p><p><table border="1"> <tr> </tr> <tr> </tr> <tr> </tr></table></p><p>Alright! Our table is all set up. We have a table with a border=1 attribute, 3 rows, and 4 columns. Let's populate it with data so you can see a proper application of the <table> tag:</p><p><table border="1"> <tr> <th>Item</th> <th>Quantity</th> <th>Rate</th> <th>Cost</th> </tr> <tr> <td>Candy</td> <td>10</td> <td>$.50</td> <td>$5.00</td> </tr> <tr> <td>Toothpaste</td> <td>2</td> <td>$3.00</td> <td>$6.00</td> </tr></table></p><p>Open the page in a browser and check out your work. Nice job! I'm truly impressed. Go eat something good and fattening.</p><p>One other fun thing you can try playing with are the colspan and rowspan attributes. If you add colspan="2" (or rowspan, or any other number) into a <th> or <td> tag, the cell will expand past their cell size. For example, <th colspan="2"> will give you a table header that spans 2 columns, and <td rowspan="3"> will yield a cell that is the height of 3 rows. Jazzy!</p><p>You can also nest tables, but I won't get into that right now. If you want to play around with the code, try adding some <tr> and <td> tags inside your current <td> tags. MaGiCal ThInGs.</p><p>Making Things Gorgeous The Wrong Way</p><p>So, your website right now looks pretty bland, and that's normal. But, we want a website that is hot, sexy, ravishing, and powerful. Yes, that's right, we want a website just like you.</p><p>So first, I will show you the wrong way to style your pages. You might ask why, but trust me, if you learn in this order, you'll understand HTML attributes a lot better, and then when you move on to CSS your mind will explode with joy. Explode.</p><p>Colors</p><p>Alrighty. Let's get frisky. Open up the 3 - Styles folder and the file style1.html. You might notice that this file is pretty bland right now, but that's what we're gonna fix. Be patient, my grasshopper.</p><p>Add this line of code in the <body> somewhere below the header tags (I made a lot for fun...): <p>This text is hot like my body</p></p><p>Oh man. Load that baby in a browser. WHAT. MAGNIFICENT. COLOR.</p><p>The first thing we'll look at is the style attribute. You can style all kind of things in that, from colors to widths to heights to borders to weights. But for now, let's just talk color.</p><p>So, you might wonder, "what the heck how does that work can I just type any color in that space where red is?" And the answer is no. You can type a ton of colors there, like blue and yellow and cyan and magenta, but you can't just say oasisorange or electricwhite and hope that that'll work.</p><p>How do you get a specific color of your liking? Well that's when you use RGB or HEX colors. This is kind of a pain to grasp, it took me a little bit, so I'll explain it as simply as I can: RGB stands for Red, Green, and Blue. You can have the values 0 to 255 in each to form pretty much any color in existance. Whoa. The way to form an RGB code similarly to the one above is simple:. In this example, there's 255 reds, 0 greens, and 0 blues. So, it's all red. Boom, simple enough.</p><p>Now HEX colors is very similar. It consists of the hashtag sign #, and then 6 hexadecimal digits, which are 0123456789ABCDEF, with F being the highest digit. Like RGB, the first two digits of HEX are reds, the second two digits are blues, and the third couple of digits are greens. So, to write the same color code above, you'd do to get red, because you have FF for reds, 00 for blues, and 00 for greens. Simple? Simple.</p><p>Don't worry, you won't have to come up with RGB and HEX colors yourself. There's plenty of websites and programs and color pickers out there to help you with that. Here's a few:</p><p>Color PickerHTML color codes and namesHTML Color CodesHTML Color Picker</p><p>Try adding colors to various tags on the page! You can make your <h1> the color #005DFC, your <h3> tag rgb(242,127,56), and your <p> tag lightblue. Keep playing til you're happy.</p><p>Now, you might see the syntax in your HTML journey where you actually have the color attribute, like <p color="red">wut</p>. Though this is technically allowed, please don't do this. Please. You'll be so much happier in the long run, I promise.</p><p>Width and Height</p><p>So, what if you want to make a picture or a paragraph a different size? Easy peasy.</p><p>There are two options you can use, the style attribute and the width and height attributes. I'll show you both.</p><p>Take this block of code here and stick it into style1.html:</p><p><img src="https://i.imgur.com/4ihC2Yb.gif" /></p><p>Now, let's just say you want the image to be an exact size, say, 600x800. All you need to do is add width and height attributes to do just that!</p><p><img src="https://i.imgur.com/4ihC2Yb.gif" width="600" height="800" /></p><p>Load that baby in a browser. Boo yah. But, you'll notice that the proportions of the image are a little off. What a pain. That's actually pretty easy to fix. Let's say that you absolutely have to have the width at 600 pixels, but the height can slide. It's as easy as taking out the height attribute.</p><p><img src="https://i.imgur.com/4ihC2Yb.gif" width="600" /></p><p>Refresh dat page. Huzzah. Same works for if you have a set height that you want, just include the height attribute and not the width.</p><p>Now, you can also do these changes with the style attribute.</p><p><img src="https://i.imgur.com/4ihC2Yb.gif" /></p><p>Simple enough! Now, we've looked at the style attribute a bit now but I haven't explained the syntax. The style attribute is for inline styles. This means that you're styling your HTML directly in each element, rather than using CSS. But, we haven't gotten that far yet, so I won't go into that part.</p><p>Now, the syntax within a style attribute is a little funky. It is always, where the property is literally a property of the tag you're editing (for example, color, width, height), and the value is to what you're changing or editing the property (for example blue, 600px, #FF0000). If you have more than one property that you want to style, for example both height and width, you put a semicolon between delarations. So, in our example, if you want to edit both height and width of our image in the style attribute, we'd do:</p><p><img src="https://i.imgur.com/4ihC2Yb.gif" /></p><p>Why is the syntax this funky? Well, that's because it's secretly CSS syntax. But we'll get into that more later.</p><p>Borders</p><p>What if we have a paragraph IN A BOX. That's right. Kind of like a table. But not. That'd be cool. Of course, there are plenty of other things that can have a border. Buttons (we'll get to those later), color blocks (also later), and images, and MORE can have them. Mmmhm.</p><p>Let's take the same image we played with before:</p><p><img src="https://i.imgur.com/4ihC2Yb.gif" /></p><p>Now, you can add border="5" to this and you'll get a border with a thickness of 5 pixels around the image. But, this attribute is actually no longer supported for things other than tables (oh yeah, we used this for tables. Memories.), so we can do this a better way. You guessed it. style is coming to SAVE THE DAY.</p><p>The styling for borders with the style attribute is a bit different than just adding border="5", but it's also much more powerful. Let's change our code:</p><p><img src="https://i.imgur.com/4ihC2Yb.gif" /></p><p>Whoa. That's a lot of crap in there. Let's break it down.</p><p>The first part of the declaration is obvious, border. This is the property that we're editing. Man, this is easy.</p><p>Next, we have 3 parts in the value section. The first part is 5px. Firstly, px stands for pixels. We used this above for our width and heights as well. You always have to include the units (just like in 5th grade math) in your styling, and our units here are pixels. Now, that whole first part, 5px, is the border's thickness. You guessed it: it's 5 pixels thick. Gosh you're smart. The next part is the border style. You can plug in several words here, as indicated on this webpage. We used solid, but you can also say dotted, dashed, or double. There are some other words you can use, but those depend on the color of the border. Color? What? OH YEAH. That's the third part of the border style. You can stick in any color for that, but in this example, we have black.</p><p>Let's mix it up a bit with different borders for you to check out. I'm just going to keep using the same image, you can replace it with whatever. Stick this in the <body> tags of style1.html and check it out, and play with the values yourself!</p><p><img src="https://i.imgur.com/4ihC2Yb.gif" /><img src="https://i.imgur.com/4ihC2Yb.gif" /><img src="https://i.imgur.com/4ihC2Yb.gif" /> <img src="https://i.imgur.com/4ihC2Yb.gif" /></p><p>Notice how I added width and height to a couple of them. We're getting incestuous with our stylings. Aww yeah.</p><p>Text Styles</p><p>Besides having header tags and colors, there are other text styles that you can use. What if you want bold text, or italics? Different sizes? Once again, the style attribute comes to the rescue.</p><p>Add the following to style1.html in 3 - Styles:</p><p><p>This text is magnificent.</p></p><p>Load that in a browser and check it out. YUS. You've got some magically centered, bolded text! The properties defined here are pretty simple to follow. text-align lets you align your text either center, left, or right. Mess around with that so you get it. font-weight, you guessed it, edits the weight in your text. It can have the values normal for normally weighted text, bold for thick characters, bolder for thicker characters (specific, right?), lighter for lighter-weighted characters, and the numbers 100, 200, 300, 400, 500, 600, 700, 800, and 900 (where 400 is the same as normal and 700 is the same as bold).</p><p>Play with this one now:</p><p><p>This text is magnificent.</p></p><p>Browser time. You've now got some text in the font Arial, and it's italic! WOOO HOOOOOO. The properties we used here are font-family and font-style. For the former, you can choose a lot of fonts, but you have to be careful. Not every computer has the same fonts. This is just my personal opinion: don't put something here besides Arial unless you've done some <a target="_blank" href="https://www.finclip.com/news/tags-97.html"style="font-weight:bold;color:#262626">JavaScript</a> magic. And because I'm assuming you don't know JavaScript, don't use this unless you're changing this to Arial. At least not yet. :) And for font-style, it can be normal, oblique, and italic. You can play with those now, it's pretty straightforward.</p><p>The <head> Tag</p><p>Before we start going insane with how good you are at HTML, let's start looking at something that you haven't played with yet. The <head> tag.</p><p>I mentioned before that in the <head> is information that the user doesn't see, so it's not that big of a deal, right? WRONG. It's not all about looks. That's at least what I try to tell people when they see me.</p><p>So. What else can go in the <head>? We've already got <title>, which we've talked about already to help search engines find us. What if we want to help the search engines out a bit more? Incoming, the <meta> tag.</p><p>The <meta> tag gives metadata about the HTML document. Metadata will not be displayed on the page, but machines can read it. An example of metadata not on a webpage is in a typical music file. When you have a music file on your computer and you open it in some media player of some kind, it shows the album title, the artist, the genre, and other information about the song. This information is metadata. The user can't see it directly in the music file, but your music players can read it and will tell you what it is. So, on a website, this metadata is used by search engines, your browser, and other web services to make your website easy to find, read, and display.</p><p>There are 4 important uses for the <meta> tag. There are plenty of other uses, but let's be honest, I don't care about them right now, and I don't think you do either. Open up the 4 - Head (heh get it? Forehead? I crack myself up.) folder, and open cooking.html in your favorite editor.</p><p>Defining keywords for search engines. Let's say that you have a website that's about cooking, hence our filename. You want people searching for your website to be able to find it. So, you can add the following right before the <title> tag:</p><p><meta name="keywords" content="cooking, cook, recipe, food, microwave"></p><p>Simple enough. Now, when people search using the terms cooking, cook, recipe, food, and microwave, your website is pushed up in the results. Nice!</p><p>Defining a description of your site. Again, this one is for the search engines. Whenever you search for a website, there's a tiny description in the search results. Go search for anything right now, and you'll see it. So, you can define what that is with this snippet:</p><p><meta name="description" content="The best cooking website in the entire universe. You're welcome."></p><p>Add this right after the keywords line in cooking.html. Now if people were searching for this, they'd get this description and instantly see that your website is the best cooking website in the universe.</p><p>Defining the author of a website. Let's say that someone's looking for the author of your website, because your writing style is sexy. Or something. You can let them know who you are with the following:</p><p><meta name="author" content="Sexy McGoodlooking"></p><p>Add this after your description line, and stick your name in it! I think I got it as close as possible.</p><p>Refreshing your document every 30 seconds. This one is for your browser. Let's say that you have comments available on your recipes, and you want to have the page refresh so the comments can appear "live". Just add this:</p><p><meta http-equiv="refresh" content="30"></p><p>And there you have it, a self-refreshing webpage. You're so good at this.</p><p>Putting it all together so far</p><p>Okay, you have a pretty solid understanding of stuff so far. I want you to take cooking.html, and make it shine. Resize the images so the page is more uniform. Add borders to them. Change the font styles and weights. Change the colors. Add some keywords in the metadata and change the title of the page. Using the information I've given you so far, you can make a pretty good looking site!</p><p>CSS is magical, and now you're gonna learn it.</p><p>So far, we've been making things pretty the wrong way. So, we're going to learn it the right way. So excited.</p><p>Right now, I'm going to show you how to write CSS just straight in your HTML documents. That's still kind of wrong, but it'll give you the basics. After that, we'll move into the big leagues and have separate files for everything. Pumped.</p><p>Open up your 3 - Styles folder again and open style2.html in your favorite editor. This site is pretty barebones. Let's take out the barebones part and just make it pretty.</p><p>We're going to be working in the <head> tag again. Underneath the <title> tag, stick in the following:</p><p><style> body { } h1 { } p { } ol { }</style></p><p>Congratulations. You have some empty CSS. Now, what the heck is CSS anyway? Well, CSS stands for Cascading Style Sheets. Gee whiz, that word style is everywhere. And it's true. The style attribute is for styling inline HTML (just that line of code), the <style> tag is for holding CSS, and CSS defines the styles! Let that sink in. Nice. Stylish. Just like you.</p><p>Now, you'll notice some familiar keywords in there, in particular, body, h1, p, and ol. That's right, they're the tags we know and love! But, in CSS, these are called selectors. The selector tells us what tag you're about to style. So, whatever code you put in between the curly braces {} after the body selector will affect everything in the <body> tags. Whatever you put in the braces after the p selector will affect what's in the <p> tags. Whatever code you have in those curly braces will only affect that tag, so if you try editing the font colors for the h1 selector, it won't affect whatever is in the p selector's tags. Each portion of code selector { code } in CSS is called a declaration. Make sense? Good. If not, keep reading and hopefully it will become more clear as we go on.</p><p>The code that we're going to be putting in each declaration is the same syntax as the code that we normally put in the style attribute. How convenient. So, change your code above to the following:</p><p><style> body { font-family: Arial; } h1 { color: red; text-align: center; } p { font-weight: bolder; } img { width: 400px; border: 5px solid #333333; } ol { color: #333333; }</style></p><p>Recognize that? It's exactly the same! For each selector, there is a property of that selector, and each property has a value, just like how we wrote it in the style attributes!</p><p>You will always have your CSS in the syntax, selector { property: value; property: value; }. I've only shown you some properties so far, but don't worry. There are plenty more to come.</p><p>Try playing around with the CSS we have right now. Edit the colors, add some borders, change the font styles. Don't forget your semicolons!</p><p>Classes and IDs and other Segregation</p><p>So, you have some of the CSS basics down already. You're so smart. It's really a simple language, once you know the basic syntax. So, now we'll get into more fancy stuff. What if you want to edit several tags differently?</p><p>Classes</p><p>Let's say that we have 8 <p> tags on our HTML page (hint: open style3.html in the 3 - Styles folder). If we want to style each of these tags differently, we can use classes. A class is actually an HTML attribute that you can name whatever you want. Check out style3.html to see the classes I added to the <p> tags on the page. When you add a class, the user doesn't see it. But, you can style specific classes to do what you want, instead of having all <p> tags be the same.</p><p>How about we style one of the classes specifically? It's simple. Just take the class name you made up (I'll use the poemtitle class for my example) and add a period . in front of it to select it in CSS, like so:</p><p>.poemtitle {}</p><p>And there you have it! Even though you might have different styles for your paragraphs, you can style the ones of class poemtitle individually. For this example, let's make all paragraphs with the font family Arial, the poemtitles font weight bolder, the authors the color #555555, and the poems in italic. Try doing it on your own if you can (just put your code in the given <style> tags), but you're welcome to cheat:</p><p>p { font-family: Arial;}.poemtitle { font-weight: bolder;}.author { color: #555555;}.poem { font-style: italic;}</p><p>Gosh you're good at this. Go eat a cookie.</p><p>[Pausing here for cookie break]</p><p>IDs</p><p>Now, let's talk about IDs. They are very similar to classes. The only real difference between classes and IDs is that you can only have one of each ID. So, for example, if you have a special paragraph that you only want to style once, then you can stick in there the id attribute like so:</p><p><p id="special">This is so special that I want it uniquely styled forever.</p></p><p>When you want to style your IDs, you put a hashtag # before it in your CSS, like so:</p><p>#special {}</p><p>Remember: You can only use an ID once. IDs are more helpful when you're controlling the element with JavaScript, not styling, but that's something for another day.</p><p>Other Segregation</p><p>Let's say that you want to separate individual text in your paragraphs or sections on your page. Let's introduce 2 new tags: <span> and <div>.</p><p>The <span> tag</p><p>The <span> tag is pretty invisible unless you style it. It's used to group inline-elements (so like a word in a paragraph), and it doesn't actually do anything unless you style or manipulate it with something else.</p><p>So, let's say you have a paragraph and you really want to emphasize some text within a paragraph without a line break or anything. In comes <span>. For example:</p><p><p>"My grandmother started walking <span>five miles a day</span> when she was sixty. She's ninety-seven now, and <span>we don't know where the heck she is.</span>" </p><p>~ Ellen DeGeneres </p></p><p>In the above quote, you might want to style the <span> tags differently than the rest of the paragraph. Maybe you want those words bold, or italics, or in red. Now you can.</p><p>Add some <span> tags around your favorite lines of the poems in style3.html of the 3 - Styles folder. Then, put the following CSS in your <style> tags:</p><p>p span { font-style: italic;}</p><p>Wait a minute. Hold up. p span?? WHY THE SPACE? Calm yourself, I'll tell you. This is called nesting CSS. When you have a space in your selector like this, it means that, in this case, the style will only affect <span> tags within <p> tags. So, if you put <span> tags around a word in your <h1> tags, your CSS will not affect it. You can still have a plain span selector, or nest it in one of your classes too:</p><p>span { font-weight: bold;}.author span { color: #999999;}</p><p>Make sense? I hope so. To sum up: <span> tags separate specific parts of paragraphs or other inline sections of a page. They do nothing otherwise. You can nest CSS if you want. Boom. Next.</p><p>The <div> tag</p><p>Alrighty. Go enjoy a beach vacation and then come back to this.</p><p>Welcome back.</p><p>The <div> tag is very similar to the <span> tag, in that it separates a section of something but doesn't do much else. However, the difference with <div> tags is that they are block level elements, not just within a line of text.</p><p>The <div> tag might end up being the tag that you use most often. It is what lets you easily make website layouts (with help from CSS of course), and so, let's play with it!</p><p>Open up the 5 - Layout folder, and use your editor to open homepage.html.</p><p><!doctype html><html> <head> <title> My Website

Besides the

tags, everything here should look familiar. Each of the have a class, which means we should style those, right? Right.

Within those