`, ``, and ` | `. Look at tables.html in your editor.
220 |
221 | 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.
222 |
223 | So, to create a table, you start with the `` tag. Simple enough.
224 |
225 | 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:
226 |
227 | ```html
228 |
230 | ```
231 |
232 | Boom. Let's add some more.
233 |
234 | The next tag we're gonna check out is ``, which is for a *table row*. Easy peasy. So, let's add 3 ` ` tags to our table.
235 |
236 | ```html
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 | ```
246 |
247 | And finally, we have the actual cells of the table. There are two types of tags for this, `` (*table header*) and ` | ` (*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.
248 |
249 | In our first set of ` | ` tags, add 4 `` tags, and in the second and third ` | ` tags add 4 `` tags.
250 |
251 | ```html
252 |
253 |
254 | |
255 | |
256 | |
257 | |
258 |
259 |
260 | |
261 | |
262 | |
263 | |
264 |
265 |
266 | |
267 | |
268 | |
269 | |
270 |
271 |
272 | ```
273 |
274 | 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 `` tag:
275 |
276 | ```html
277 |
278 |
279 | Item |
280 | Quantity |
281 | Rate |
282 | Cost |
283 |
284 |
285 | Candy |
286 | 10 |
287 | $.50 |
288 | $5.00 |
289 |
290 |
291 | Toothpaste |
292 | 2 |
293 | $3.00 |
294 | $6.00 |
295 |
296 |
297 | ```
298 |
299 | Open the page in a browser and check out your work. Nice job! I'm truly impressed. Go eat something good and fattening.
300 |
301 | 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 `` or ` | ` tag, the cell will expand past their cell size. For example, ` | ` will give you a table header that spans 2 columns, and ` | ` will yield a cell that is the height of 3 rows. Jazzy!
302 |
303 | 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 ` | ` and `` tags inside your current ` | ` tags. MaGiCal ThInGs.
304 |
305 | ### Making Things Gorgeous The Wrong Way
306 |
307 | 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.
308 |
309 | 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.
310 |
311 | #### Colors
312 |
313 | 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.
314 |
315 | Add this line of code in the `` somewhere below the header tags (I made a lot for fun...): ` This text is hot like my body `
316 |
317 | Oh man. Load that baby in a browser. WHAT. MAGNIFICENT. COLOR.
318 |
319 | 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.
320 |
321 | 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.
322 |
323 | 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: `style="color: rgb(255,0,0)"`. In this example, there's 255 reds, 0 greens, and 0 blues. So, it's all red. Boom, simple enough.
324 |
325 | 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 `style="color: #FF0000"` to get red, because you have FF for reds, 00 for blues, and 00 for greens. Simple? Simple.
326 |
327 | 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:
328 |
329 | * [Color Picker](http://www.colorpicker.com/)
330 | * [HTML color codes and names](http://www.computerhope.com/htmcolor.htm)
331 | * [HTML Color Codes](http://html-color-codes.info/)
332 | * [HTML Color Picker](http://www.w3schools.com/colors/colors_picker.asp)
333 |
334 | Try adding colors to various tags on the page! You can make your `` the color `#005DFC`, your `` tag `rgb(242,127,56)`, and your `` tag `lightblue`. Keep playing til you're happy.
335 |
336 | Now, you might see the syntax in your HTML journey where you actually have the `color` attribute, like ` wut `. Though this is technically allowed, please don't do this. Please. You'll be so much happier in the long run, I promise.
337 |
338 | #### Width and Height
339 |
340 | So, what if you want to make a picture or a paragraph a different size? Easy peasy.
341 |
342 | There are two options you can use, the `style` attribute and the `width` and `height` attributes. I'll show you both.
343 |
344 | Take this block of code here and stick it into style1.html:
345 |
346 | ```html
347 |
348 | ```
349 |
350 | 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!
351 |
352 | ```html
353 |
354 | ```
355 |
356 | 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.
357 |
358 | ```html
359 |
360 | ```
361 |
362 | 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`.
363 |
364 | Now, you can also do these changes with the `style` attribute.
365 |
366 | ```html
367 |
368 | ```
369 |
370 | 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.
371 |
372 | Now, the syntax within a `style` attribute is a little funky. It is always `style="property: value"`, 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`).
373 | 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:
374 |
375 | ```html
376 |
377 | ```
378 |
379 | Why is the syntax this funky? Well, that's because it's secretly CSS syntax. But we'll get into that more later.
380 |
381 | #### Borders
382 |
383 | 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.
384 |
385 | Let's take the same image we played with before:
386 |
387 | ```html
388 |
389 | ```
390 |
391 | 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.
392 |
393 | 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:
394 |
395 | ```html
396 |
397 | ```
398 |
399 | Whoa. That's a lot of crap in there. Let's break it down.
400 |
401 | The first part of the declaration is obvious, `border`. This is the property that we're editing. Man, this is easy.
402 |
403 | 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.
404 | The next part is the *border style*. You can plug in several words here, as indicated [on this webpage](http://www.w3schools.com/css/css_border.asp). 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.
405 | 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`.
406 |
407 | 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 `` tags of style1.html and check it out, and play with the values yourself!
408 |
409 | ```html
410 |
411 |
412 |
413 |
414 | ```
415 |
416 | Notice how I added `width` and `height` to a couple of them. We're getting incestuous with our stylings. Aww yeah.
417 |
418 | #### Text Styles
419 |
420 | 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.
421 |
422 | Add the following to style1.html in **3 - Styles**:
423 |
424 | ```html
425 | This text is magnificent.
426 | ```
427 |
428 | 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.
429 | `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).
430 |
431 | Play with this one now:
432 |
433 | ```html
434 | This text is magnificent.
435 | ```
436 |
437 | Browser time. You've now got some text in the font Arial, and it's italic! WOOO HOOOOOO.
438 | 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 JavaScript 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. :)
439 | And for `font-style`, it can be `normal`, `oblique`, and `italic`. You can play with those now, it's pretty straightforward.
440 |
441 | ### The `` Tag
442 |
443 | 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 `` tag.
444 |
445 | I mentioned before that in the `` 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.
446 |
447 | So. What else can go in the ``? We've already got ``, 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 `` tag.
448 |
449 | The `` 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.
450 | 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.
451 |
452 | There are 3 important uses for the `` 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.
453 | Open up the **4 - Head** (heh get it? Forehead? I crack myself up.) folder, and open cooking.html in your favorite editor.
454 |
455 | * *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:
456 |
457 | ```html
458 |
459 | ```
460 |
461 | 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.
462 |
463 | * *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:
464 |
465 | ```html
466 |
467 | ```
468 |
469 | Add this after your description line, and stick your name in it! I think I got it as close as possible.
470 |
471 | * *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:
472 |
473 | ```html
474 |
475 | ```
476 |
477 | And there you have it, a self-refreshing webpage. You're so good at this.
478 |
479 | ### Putting it all together so far
480 |
481 | Okay, you have a pretty solid understanding of stuff so far. I want you to take cooking.html, and make it shine.
482 | 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.
483 | Using the information I've given you so far, you can make a pretty good looking site!
484 |
485 | ## CSS is magical, and now you're gonna learn it.
486 |
487 | So far, we've been making things pretty the wrong way. So, we're going to learn it the right way. So excited.
488 |
489 | 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.
490 |
491 | 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.
492 |
493 | We're going to be working in the `` tag again. Underneath the `` tag, stick in the following:
494 |
495 | ```html
496 |
505 | ```
506 |
507 | 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 `
538 | ```
539 |
540 | 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!
541 |
542 | 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.
543 |
544 | 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!
545 |
546 | ### Classes and IDs and other Segregation
547 |
548 | 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?
549 |
550 | #### Classes
551 |
552 | Let's say that we have 8 `` tags on our HTML page (hint: open style3.html in the **3 - Styles** folder).
553 | 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.
554 | Check out style3.html to see the classes I added to the ` ` tags on the page. When you add a class, the user doesn't see it.
555 | But, you can style specific classes to do what you want, instead of having all ` ` tags be the same.
556 |
557 | 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:
558 |
559 | ```css
560 | .poemtitle {
561 |
562 | }
563 | ```
564 |
565 | And there you have it! Even though you might have different styles for your paragraphs, you can style the ones of class `poemtitle` individually.
566 | For this example, let's make all paragraphs with the font family Arial, the `poemtitle`s font weight `bolder`, the `author`s the color `#555555`, and the `poem`s in `italic`.
567 | Try doing it on your own if you can (just put your code in the given `
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 | ```
672 |
673 | Besides the `` tags, everything here should look familiar. Each of the ` ` have a `class`, which means we should style those, right? Right.
674 |
675 | Within those ` | | |