Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Now technically, I know we styled our table headers in the last movie, but there remains, as you can see in our table here, a lot of work to be done. Well currently, there is nothing in our styles that differentiates our table headers from our table data. Other than the font size, they pretty much look the same. As a general rule, this is a bad idea, since users should be able to quickly scan our tables to find the data. Without being able to identify our headers easily, establishing relationships between the data is going to be difficult.
Since we've removed any default styling that identifies our headers, we will return to them and the thead element to add our header styling. So here we have the bigsur_trails file open and what we are going to do is we are going to go over to our CSS Styles panel. I am going to collapse the Files panel, and we are looking for our table styles. Now, if you remember in the last movie, we placed them right above the Spotlight region. So we should have three of them right here, data, the th and the td selectors. Well the th selector is the one that we are interested in.
So go ahead and highlight that one. #mainContent table.data th. You can see a list of your properties right here if we are in All view and this is going to be a fast and easy way to add additional properties to this particular rule. So what I want to do is add a new property. I am just going to click right there on that link and I am going to add the color property. Now remember, you can grab that pull- down menu and choose color as well. I am going to hit Tab to go down the next line, and the color I am going to add is #fff, which is white.
As soon as you do that, your table headers go away. Well, not really, but the text is white and on a white background that's not going to show up all that well. So let's add another property and the property we want to add here is the background property. And for background, type in #555, which is a dark gray. Aha, now they show up. And that's a really nice way of differentiating our table headers from the table data itself. Very quickly, very easily, anybody could scan that and figure out kind of what's going on there.
Well that's nice, but I would like another level of differentiation. How about being able to differentiate between the name of a trail versus the data up top where the Trail Name, Type, Length, Path, Elevation, and Rating are being listed. Well remember, the table row up top that contains those table header cells is surrounded by a thead tag. We can use that to our advantage by creating an additional rule. So with our th tag rule right up here still highlighted, go down to your CSS Styles panel and click New CSS Rule.
Once again, make it compound but just ignore anything that comes up here. This is a really long string, and we don't need it to be quite that long. Type in #mainContent table.data thead, all one word. Now, the only downside to writing out these long compound or descendent selectors all by yourself is that spelling counts. Spelling, capitalization, spaces, dots, punctuation, all of it matters.
So if you're not familiar with writing selectors quite as complex as this, take a moment, pause the screen, and just go through there character for character and make sure that you are getting everything right where it needs to be. Just as a way of sort of explaining this, this is looking for any thead element inside of a table with a class of data assigned to it, inside of any element with an ID of mainContent. So it's pretty specific. I am going to go ahead and click OK, and here I'm going to go to my Box category and I am going to change the height to 40 pixels. Interesting! Now, the reason we're doing that is because instead of just using a boring old background color, we are going to use a background graphic.
So I am going to go to he Background category and I'm just going to browse for a background image and I want to go inside the 11_06 folder, _images, and I am just going to turn those to Details so I can see them a little bit clearer. And what I am looking for-- I am just going to expand my names here a little bit. What I am looking for is the thead_back.gif. And if I look at the preview of that, it's a pretty small graphic. It's 5 pixels wide. Aha, 40 pixels tall.
So now we know why our table head needs to be 40 pixels tall as well. And it is again fairly small. only 5 pixels wide. So I am going to click OK. And what we are going to do now is we are going to do a background-repeat of repeat-x. That's going to tile this graphic along the X-axis which is going to make it look like one seamless gradient all the way across. And when we click OK, we see nothing. Well, that was a little anti-climactic, wasn't it? So how come we are not seeing anything.
I want you to think of these table elements as sort of sitting on top of one another. The table would be at the very bottom, for example. And then the table cells would sort of sit on top of that. So if you gave your table a background color, but then gave your table data tags the background color, you wouldn't see your table's background. The same thing is happening here. The thead tag is sort of sitting underneath the th tags sitting on top of it. So that gray background color is sitting on top of the thead tags is covering up our really cool orange gradient.
So what are we going to do here? Because if we remove the background color from the th tags, well it would remove it here, which is where we want it. Well, not all is lost. Remember, using cascading style sheets, you can write some pretty precise selectors. So what we are going to do is we are going to write another selector that targets only the table header cells inside the thead tag. All right. So once again I am going to go right over here to the CSS Styles panel. I'm going to make sure that I have the thead tag highlighted, because I want my new rule to appear just underneath this one.
I am going to choose New CSS Rule, and I am just going to type in #mainContent table.data thead th. So it's almost exactly identical to the last one, we are just adding another table header element right there on the end of it. Now, go ahead and click OK. And for color, we want to type in #000, so the text will be black on top of that orange gradient. Now go to Background and actually these guys don't need a background color so it would be very tempting to go into my background-color here and choose transparent.
But there is actually an easier way to do this. Unfortunately, it doesn't allow us to do it through this dialog box. So what I am going to do is I am going to go ahead and click OK and then using the CSS Styles panel, I am going to add another property and I am going to add background, none. Easy enough. Now, we will just do a Save All. And you might be saying to yourself, wait a second, I thought we were supposed to see a cool orange gradient behind our top header cells, what's the deal? Well, Dreamweaver's Design View does a pretty good job of rendering most things, but it does a horrible job of rendering background images on thead tags.
I don't know why, but it just doesn't do them. So what I would like you to do is go up and turn Live View on, scroll back down again, and there you should see your table header's gradient in all its gradient goodness. So now we are getting somewhere. Our headers are fairly distinct from the rest of the table and they are generating some real visual interest. There is some pop there. Notice that the top headers and side headers have separate but related styling, which signals intent and relationships visually. Now that we have taken care of our headers, we need to turn our attention to making the table data itself a little bit more visually appealing.
Get unlimited access to all courses for just $25/month.Become a member
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.