Start learning with our library of video tutorials taught by experts. Get started
Viewed by members. in countries. members currently watching.
In XHTML and HTML Essential Training, Bill Weinman helps designers and coders understand XHTML and HTML. In the process, Bill covers document structure, block and inline-level tags, floating images, controlling white space, phrase and font markup, and tables and frames. He even provides a good introduction to CSS. Bill offers step-by-step guidance for building a complete working web site. Exercise files accompany the course.
Continuing with the development of our example website, in this lesson we are going to insert the header and the contact button. So looking at the browser here, basically what we are going to do is the top half of this table cell here with the Contact button in it. That's what's called a Mail To link. So when you click on this, it would open your mail client and allow you to send an email message. It's a simplest form of a contact button. So let's get started. We have here beginning.html and our beginning.css and this is in the 03-Contact folder of the Chapter 09 Exercise Files.
The first thing we are going to do is we are going to Save As. We'll save as heading.html. This way we don't overwrite our Exercise Files and do the same thing with the CSS. Save that as main.css, because that's the name that gets used here in the XHTML. Now we'll go ahead and enter some content in here. We are going to create the outer table and we are going to create the table cell for the Contact button.
So this table tag has an id attribute and that creates a CSS id selector. I'd like to close my containers when I start them. So this row has one cell in it. So I've opened it and closed it and you'll notice that for my selectors, I'm using what's called camelCase. And this is actually a very good choice for CSS, because CSS doesn't allow dashes and I happen to be one of those people that dislikes typing underscores. I do it when I have to and I have too often, because other people use them. So I like camelCase for CSS and it allows me to have several words as very nice descriptive selectors and so camelCase usually uses a lowercase to begin and it uses uppercase letters at the beginnings of second and subsequent words.
So I have outerTable, I have contactButton and this is what's called camelCase. Go ahead and create a div. We'll talk about all this organization in a moment here and the anchor tag. Ending my anchor tag on the second line and that allows me to put it right up against the image and we talked about that in our chapter on images. You'll notice I inserted width and height attributes for the image and I have those numbers already, because all these assets were given to me. So I have those in my notes.
It's a really good idea to always include the width and height, if you can. That allows the browser to layout the page before it downloads the assets from the server so that the page loads without blinking and moving things around as it goes along. It's just a nicety and I closed the image on the next line and closed the anchor right after, so there is no space between the image tag and the anchor either at the beginning or the end. Now as we create our CSS, you'll see that I'm able to select this div specifically without it having a name, and I'll show you how we do that in the CSS.
Let's go ahead and enter some more CSS here. So again it's a section for the Contact button and I have got another section before that for the outerTable. So first the outerTable. It sets the selector for the outerTable and it has a margin 0, auto. Again, we have two values. The first value is top and bottom and the second value is the right and left.
Selecting auto for right and left that centers the table on the page and so this is what creates this effect here with it being right up against the top, but centered horizontally on the page and that's from having margins 0 and auto like that. 770 pixels wide, which is the width of all those images that are used to create the look. And this creates the image at the top of the page, so let's save this and take a look at the page over here. This image up here is actually the background image for that header table cell and this fff is the background color for the whole rest of that outerTable.
So you see that all of this white here is as a result of that. Now let's go ahead and enter the contactButton. There is our contact button selector, which we typed in the XHTML so that height is actually half the height of the image. That image with the head of the table there is 110 pixels high and so 55 is half of that, because the top half of it is what we are using for that contactButton. The bottom half we'll do in our next lesson for the menu there.
This is how we select that div. Remember we put a div in the HTML here that's inside of the contactButton, the selector of having the contactButton id selector followed by the div tag selector. That means that this is any div inside of that id selector. So any divs inside of this, which is here and here, which is this and this, will be selected by that combination selector.
It's a hierarchical selector where we have the contactButton and then div. So that's any div inside of the context of that contactButton selector. 30 pixels is the height of that image. This is a margin that basically says no margin, top, right, bottom, and 650 pixels to left so that will move it in. 650 pixels and it will be against the top of the table cell, because we have our default set to vertical align top over here. padding=0 and then finally, the contactButton image itself.
So again this is a hierarchical selector that selects any image inside of that contactButton context, which is just the one image. We'll set its margins to 0 and its border to none, so it won't get highlighted by the anchor tag around it. So that is our CSS, we'll go ahead and load it in the browser and see what it looks like. So we'll drag heading.html into the browser and you'll see that top half of the image is visible because that's the only table cell that we have defined and there is our contactButton.
So by having our table cell just be 55 pixels high, we are only seeing the top half of the image there in the browser. If we were to just make this 110 pixels, we'd see the whole header image. See there it is. But we need to make it just half as high so we can make the next table cell for the other half for the menu. Save that, and there we are done. That is our Contact button. In the next lesson, we'll do the main menu.
Find answers to the most frequently asked questions about XHTML and 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.