HTML Blox

Providing the building blox of the web.

  • HTML Blox Home
  • Blog
    • Design
    • Flash
    • General
    • HTML
    • Javascript
    • PHP
    • Programming
    • Web Servers
  • Forums
  • Where to Start?
  • Lessons
    • CSS
    • Design
    • HTML
    • Javascript
    • Programming
  • References
    • HTML
  • Resources
  • About
  • Contact
  • Go Green!

HTML Lessons

  1. Lesson 1 - The Basics
  2. Lesson 2 - Say Something!
  3. Lesson 3.1: Lay It Out! - Images
  4. Lesson 3.2: Lay It Out! - Divs & Spans
  5. Lesson 3.3: Lay It Out! - Tables
  6. Lesson 4: Don't Touch This!
  7. Lesson 5: Interact A Lil' With Flash
  8. Lesson 6.1: Forms to Fill - Form Basics
  9. Lesson 6.2: Forms to Fill - Inputs
  10. Lesson 6.3: Forms to Fill - Text Areas and Selects

HTML Reference

  1. DOCTYPE
  2. HTML Element

Links

  • W3C HTML 4.01 Strict Compliant
  • W3C CSS 2.1 Compliant
  • Web Standards Group Member
  • Follow us on Twitter
  • Number Overflow - Free Advanced Scripts and Tutorials
  • Azure Ronin Web Design - Professional Web Design and Development
  • XML Sitemap
  • U Comment, I Follow

Feeds

  • RSS 2.0 Feed
  • RDF/RSS 1.0 Feed
  • RSS 0.9 Feed
  • Atom Feed

Lesson 3.2: Lay It Out! – Divs & Spans

del.icio.us Digg Blinklist reddit

In the last lesson you learned how to add images in a contextual format and we discussed using images in a decorative context.

Now, we’ll discuss the use of Divisions (Divs) and Spans, the two basic “container” elements used to lay out pages.

Container Elements

Container elements are elements which are simply meant to contain other elements. By default, they have no visual representation on their own, and are only meant for positioning other elements on the page. Divisions and spans are these type of elements. The two are actually very similar with one key difference: divisions are block-level elements and spans are inline elements.

Block-level versus Inline

Elements in web pages have two general behaviors: block-level or inline.

Block-level elements (like divisions), by default, will usually try to take up the entire width of whatever they are contained within and will force any other elements on the same line as them down below them. So, if you had this code:

Code

<div>Something here</>
<div>Something else</>

The first div would take up 100% of the width of the line it is on, and push the second div down below it, which would also take up 100% of the width. Headers and paragraphs are also block-level elements.

Inline elements, like spans, are “inline”, meaning that they simply line-up where ever they are put, taking as little space as they can and trying not to move other things around. Images are another inline elements.

Usually, you would use inline elements within block-level elements.

Divisions

Divisions use the <div> tag. They have only two important attributes: id and class. Both of these are used as CSS hooks, which we’ll cover in our first CSS lesson. Whatever you want contained within a division, such as paragraphs and images, you would place between the <div> tag and it’s closing </div> tag.

Without CSS, divisions have little value. We’ll cover how to manipulate them with CSS in one of our CSS lessons very soon.

Spans

Spans use the <span> tag. Like divisions, they also only have two important attributes: id and class, both of which are used as CSS hooks. They also contain their information within their opening and closing tags (</span&gt).

And, also like divisions, without CSS, spans have little value.

While divisions can contain just about any element, including more divisions, spans have a much limited range and can only contain inline elements like simple text and images. These would be some valid uses of spans:

Code

<h1><span>Something</span>&lt/h1>
<p>Something <span>else</span></p>
<div><span><img src="apic.png" alt="A pic"></span></div>

In our next HTML lesson, we’ll cover using tables, the last of our layout elements. Be cautious though, because tables aren’t meant to be used as layout for the entire page, even though it is sometimes easier than usual. Some sites may tell you to use tables, but don’t. Tables are only meant for tabular data, which is what we’ll discuss their use for: Lesson 3.3: Lay It Out – Tables

Now would be a good time to move on and complete the first several CSS lessons as well, so you can learn how to use divisions and spans to actually do something.

This entry was posted on Monday, August 4th, 2008 at 10:09 am and is filed under HTML Lessons. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Please Login or Register or fill out the following to leave a reply:

If you haven't posted an approved comment before, your comment will not show up until approved.

  • HTML Blox Home
  • Blog
  • Design Blog
  • Flash Blog
  • General Blog
  • HTML Blog
  • Javascript Blog
  • PHP Blog
  • Programming Blog
  • Web Servers Blog
  • Forums
  • Where to Start?
  • Lessons
  • CSS Lessons
  • Design Lessons
  • HTML Lessons
  • Javascript Lessons
  • Programming Lessons
  • References
  • HTMLReferences
  • About
  • Resources
  • Contact
  • Go Green!
  • Sitemap

Copyright © 2008 HTML Blox

Unless otherwise noted, all images created and copyright HTML Blox.

Operated by Azure Ronin Web Design