Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
This course introduces web designers to the nuts and bolts of HTML (HyperText Markup Language), the programming language used to create web pages. Author Bill Weinman explains what HTML is, how it's structured, and presents the major tags and features of the language. Discover how to format text and lists, add images and flow text around them, link to other pages and sites, embed audio and video, and create HTML forms. Additional tutorials cover the new elements in HTML5, the latest version of HTML, and prepare you to start working with Cascading Style Sheets (CSS).
In the book Creative HTML Design that Lynda and I wrote back in the '90s, we presented an example of an image that had been chopped up and reassembled using HTML tables. This was a common technique in those days because it allowed parts of the image to be used in different ways. This movie presents some HTML5 compatible way to accomplish the same thing today. If we open this folder called cutapart in the Chap06 folder of the exercise files you'll see two versions of this example. One version uses tables and this is basically the way that we did this back in the '90s.
It's a little bit different than our original example, because some of the tags and attributes are better defined today in HTML5, than they were back then, but this is valid HTML5, and it uses a combination of tables and stylesheets to accomplish this. I am just going to open this up in the browser and you'll see what looks like an image, but you will notice it's made up of 12 different images that are all summed up together in a table. And if we look back here in this folder, under images you see here are these 12 images.
I am going to use the QuickView feature here on this Mac and we can look at each of these images as I scroll down the list. And you see these are all the different parts of that one image. And then here's the whole image. So that's the table's version. What I am going to show you now is the HTML5-ish way to do this. And there it is in the browser, and here it is in our text editor. It's actually a little bit simpler. It's a little bit smaller, it has a few less lines of code, and you can see it's actually very clear.
All we have here is a set of divs and the images, and everything else is done in the CSS and really just with a couple of lines of CSS. And here it is in the browser, exactly the same result. In each of these images if I do a view image, you will see they are all the little pieces of the image. So here's how this works. We have a div with a class called cutapart. And that's really only used for context. In CSS, I am using descendent selectors, so where crow is a descendent of cutapart, this style will be applied which basically just has a clear.
And where image is a descendent of cutapart, it changes the image to block mode and floats it to the left. Actually if I just float it to the left, it will make it block mode anyway. I just put this in also to remind myself that that's what it's doing. And that's all there is to it. So in each of these div class crow, we have a number of images and these images float left, and then they clear, and the clear happens because the clear is in the crow.
So when the next crow shows up, we get a clear. And then a number of images that are floating left, and when you float objects next to each other, all in the same direction, they stack up in that direction. And so all this is doing is it's stacking up image, image, image, image, image and then image, image, image, image, like that in these different rows. You can see it a little better. If I go ahead and put a border on the image and we reload this, you can see each of the images now has this red border and you can see all the pieces of them.
So these four stack up in the first crow, these four stack up in second crow and
these four stack up in the third crow.
Now this technique does have one problem.
We'll go ahead and take that border off and reload over here.
If I come up here after all of this and I say this is a paragraph of text.
this is a paragraph of text.And I save that and load it up; you will notice that the text comes up here in the last crow, because the last crow is floated to the left. And so what this requires is a clear. Now I could create a class up here called clear, and then I can put that class on this paragraph and that would actually solve the problem.
And I hit a Reload here and we see now the paragraph is down there. The problem with this solution is that it's not consistent enough. It's not repeatable enough. It would be easy for me to forget to put this clear in and to forget why this is a problem and to end up having to reinvent the wheel. What I really need is something that I can put inside of here. So what I've done, and I actually do this in most of my stylesheets, because I come across this kind of problem often enough. I create a class called clear that does this.
It makes it possible for me to have an object like a paragraph or a div or
something and I'll usually--I am just going to take this out of here and I am
going to close this paragraph like I am supposed to.
I am going to come up in here and I am going to just say
And now all I have to do is remember to put that in every time I do this pattern,
and you'll see that it works perfectly.
I will Reload this and there is my paragraph.
And in this case, I have a normal paragraph here and it's got the leading
above it just like I would expect and it actually looks exactly like it's supposed to look.
So now we have a good repeatable pattern, it's got a manageable amount of
CSS, and it solves the whole problem and allows us to assemble our images in a very simple way.
So this technique can be handy for manipulating parts of an image, say with
animation or rollovers.
It also demonstrates just how powerful the combination of HTML and CSS can be
when used thoughtfully.
And now all I have to do is remember to put that in every time I do this pattern, and you'll see that it works perfectly. I will Reload this and there is my paragraph. And in this case, I have a normal paragraph here and it's got the leading above it just like I would expect and it actually looks exactly like it's supposed to look.
So now we have a good repeatable pattern, it's got a manageable amount of CSS, and it solves the whole problem and allows us to assemble our images in a very simple way. So this technique can be handy for manipulating parts of an image, say with animation or rollovers. It also demonstrates just how powerful the combination of HTML and CSS can be when used thoughtfully.
Find answers to the most frequently asked questions about HTML Essential Training.
Here are the FAQs that matched your search "":
Sorry, there are no matches for your search ""—to search again, type in another word or phrase and click search.
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.