Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
You may have noticed that there aren't a lot of divs on our page. In fact, you've probably picked up on the fact that we haven't used any. This is in stark contrast to HTML 4 and XHTML documents, where a div really was the primary way to group and organize content. The variety and richness of the sectioning and grouping content elements in HTML5 means that we don't really have to rely on the div tag to do the heavy lifting anymore. Of course this doesn't mean that we are just going to forget about the div and never use it anymore.
There are still some very legitimate reasons for using it. So we are going to take a quick look what the specification has to say about the div and then come back into our page and see where it's appropriate. So here I am back at the HTML5 author-view spec and I have navigated down to the div element. And there are a couple things that I want to point out here. Notice it's flow content, not sectioning content, and it can contain anything that's in flow content inside of it. So it's really, really generic, and you can use it with just about anything. Okay, I am going to scroll down a little bit for its definition. This is where it kinds of gets sad.
The div element has no special meaning at all. It represents its children. That's basically about it. It can be used with class, language, title attributes to markup semantics common to a group of consecutive elements. Okay! Now, it's the note that I really want to pay attention to. Authors are strongly encouraged to view the div element as an element of last resort, for when no other element is suitable. And it does mention here, I can't say I was going to say that, but it mentions use of the div elements instead of more appropriate element. So using instead of say a section or an article element leads to poor accessibility for readers and poor maintainability for authors.
And you know it's easier for me to point this out in the browser rather than the structure so let me go ahead and get preview this. So I am going to go ahead and preview this in one of our browsers. I haven't used Chrome yet, so let's not pick on Chrome. Let's use it. If I scroll down to the footer, I can see the footer is--there is no other way to put it, the footer is kind of ugly at the moment, so everything is just sort of stacked on top of each other. What I would like to do, what I really like to do with the footer is I'd like to have the footer in a two-column view. I would like to have the phone number and the email address and the return to top link, all that stuff, over on the right-hand side, and I would really like to have the address on the left-hand side.
Now an easy way to do that is to use a div tag for each of those, segment them, structure them using a div tag and put them on either side. Now I could use a section element here. But again, the problem with a section element was it would now show up in the outline, and we don't want a footer in the outline. So let me go ahead and close our browser window, and we'll go back into our trails page, scroll all the way down to our footer, and we are going to start using our div tag. Okay, so essentially we are just going to group some content here with the div tag. So right inside the footer, I am going to open a div tag.
And I am going to go ahead and identify the div tags through the use of a class attribute. So I am going to give this one a class of right column, rightCol, so lowercase r, uppercase Col, rightCol if you will. And then remember this is just going to be going all the way down to say the email address. So there I am going to go down and close my div tag. So just above the all content copyright 2001 Explore California, I'll open up another div tag, and as you can probably guess this one, this one is going to get a class of leftCol.
And then at the very bottom of the footer, I'll go ahead and I'll close that div tag. So essentially, we've segmented, or sectioned if you will, or footer into two sections, a right column and a left column, and we've done that by above using the div tag. And it's going to give us a couple of advantages here. So I am going to save this, and I am going to preview this in a browser that I can check the outline in locally. So I am just going to preview this in Opera, and if I scroll down towards the bottom, I can see that we now have our two-column layout So we already have the CSS written that's basically a floating this column to the right and floating that column to the left, that sort of thing.
And if we go up and check our document outline, we can see that the footer is still not added to the outline. That's perfect! That's exactly what we want. So the divs are playing a very important role for us here. They are sectioning and structuring our content without actually creating a brand-new section in the outline, and they are allowing us to style this the way we want to without adding a ton of unnecessary markup. Now you may not use the div tag as much as you have in the past, but it does remain a really important tool for web authors. It's a great way of grouping content together without creating new sections in your document, and this can be extremely helpful for styling, like we are doing here, or just in adding an extra measure of organization to your content.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101167 Viewers
61 Video lessons · 87925 Viewers
71 Video lessons · 71806 Viewers
56 Video lessons · 103670 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.