Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

ID selectors

From: Dreamweaver CS3 Essential Training

Video: ID selectors

There will probably come a time when you want to style one specific element on a group of pages, such as a navigation bar, or a background color, or a logo, or even a footer that's displayed on every page of the site. This one element should be treated differently than anything else on your site. Now after you learn about class selectors, your immediate solution might be to create a class selector, and apply that class to the footer inside each page. But a more elegant and semantically correct approach is to give the element a unique ID, and then style just that specific element. The more specific you are with your rules, the less likely you are to have issues with something getting incorrectly styled. Now, in this particular example, this is what would show up in your actual style sheet.

ID selectors

There will probably come a time when you want to style one specific element on a group of pages, such as a navigation bar, or a background color, or a logo, or even a footer that's displayed on every page of the site. This one element should be treated differently than anything else on your site. Now after you learn about class selectors, your immediate solution might be to create a class selector, and apply that class to the footer inside each page. But a more elegant and semantically correct approach is to give the element a unique ID, and then style just that specific element. The more specific you are with your rules, the less likely you are to have issues with something getting incorrectly styled. Now, in this particular example, this is what would show up in your actual style sheet.

Now the pound symbol identifies the selector as an ID selector. The text following the pound symbol is the ID of the elements. So the ID in this case is #divCopyright. That's the name of the ID. So the element that appears on your page with the divCopyright attribute will be styled with this particular font size, margin and text alignment. So for example, if this line appears in my XHTML code,

, just like we see up here. The text that actually appears on this page is, "This is the site copyright." This text here will appear in font size of 10, margin of 1em, and text aligned will be centered. No other element in this page will have the same style applied to it, since ID selectors should be unique in each document. You should never have more than one element with the same ID. In some cases, it may work, but you might also have situations where it will crash browsers. So definitely do not use a single ID more than once per page. So let's go back to Dreamweaver.

So the power of ID selectors is that they let you target specific areas of your page for styling. So, in this movie we will take a look at the how to set IDs on elements that we want to style, as well as how to define these ID selectors to do the actually styling. I'm still working with the abouttea.html file we were working on a previous movies. Now, right now we have our layout inside of a table. So what we're going to do is we're going to style each of the table cells for the layout. Each cell will have an ID that uniquely identifies it on the page, and each table cell will get its own style, because this particular style holds the navigation. This one holds the logo, this one holds the main content, and this cell holds the links. By sending ID styles, it ensures that only one specific element gets styled. To begin using ID selectors, we need to add some IDs to the document. I'm going to click anywhere inside the table and down here in the Quick Tag Area I'm going to click the table tag to select the entire table. Down the Property inspector, I want to give my table an ID. And that field is right here. We'll call this tableLayout. You notice there's a menu option here, and this actually identifies all of the ID selectors defined in the style sheet, which is helpful because if you create your ID selectors first, then you can simply choose them from the pop-up menu. Since we only have created one so far, only one appears in here. Also, since ID selectors are case sensitive, choosing them from the menu here means you don't have to worry about typing them incorrectly. As a general rule, it's best to name your ID selectors with the tag first and then the purpose for that particular tag. So that's why I call this the tableLayout, because we're going to be redefining the table that contains the layout for the entire page. So, it's very descriptive to have tableLayout there. Okay, so let's go over to the CSS Styles panel and we're going to click New CSS Rule, and this time are going to make sure we have Advanced selected. And you're going to notice that since I just created that ID, that {italic}Dreamweaver{plain} has already filled out the information that I need here. It's got Advanced selected and the selector is #tableLayout.

and we want to make sure we attach this file to our current style sheet. Let's click on OK. Let's go over to the Background category. And for the Background color, I'm going to choose plain white. And we'll see how that looks in a moment. Let's go over to Border. I'm going to uncheck the Same for all option under Style, Width, and Color, because I want the borders around the top, right, bottom and left to be a little bit different in each case. I want the Style for Right to be solid. We'll make the width one pixel. Now, the color we're going to choose is going to be #B0B0B0, which is just a light gray color. I'm going to do the same thing for the left border.

We'll make it solid, 1 pixel and we'll choose that same color. And I'm going to go ahead and add this new rule by clicking OK. And you can see now that the table background has become white, while the page background remains that gray. And this radically transforms, and I think improves, the appearance of the page. This table layout selector we just created affects only the elements with that specific ID. So, because we applied that ID to this table, that style is automatically applied. If I preview this in my browser, I'm just going to make sure I save my styles first and then come in here and save this page, I'll preview this in my browser, hit a refresh and, there it is. And if you look closely, you should see the very thin, light gray border that we added the left and right side. Let's come back in here. Next, I want to make some changes to the navigation bar cell at the top of this page here. And we're going to define the style in the opposite order that we just defined the table in, just so you can see how you can create your ID selectors in both directions. So let's create the rule first, before we add the ID.

I'll come in here and create another new style. And we're going to call this #tdNavigation, for table cell. This is the navigation cell. Making sure we're defining this in our current style sheet. I'll click on OK. Let's go over to the Background area again. And let's set another Background color for this cell. And I'm just going to sample the color that's already in here, so the cell will actually match the color of the images in here. Let's go over to the Block category. I want to make sure that these buttons that we see here are going to be centered. So let's go to Text align > center. Even though it says Text align, it's also just regular alignment that applies to images as well. And let's go over to the Box category. In here I'm going to uncheck Same for all for Padding and I'm going to type 0 in the Bottom field. That's going to ensure that the navigation images are going to be completely flush with the bottom of the table cell. I don't want any gaps or spaces down there. And we'll be talking more about paddings and margins we get to the chapter on tables. Alright, let's click on OK. Now notice nothing has changed yet, even though that #tdNavigation style now appears in my style sheet, because we haven't added the ID to anything.

The ID definition is ready, but we haven't actually created the ID. So I'm going to click anywhere inside that cell containing the navigation. Click the tag selector down here. I'm going to right-click on it, and from here, we can actually choose to Set ID, and this shows me all the IDs I've created on this page so far. And in this case, I want to give it the tdNavigation ID. Once I do that, the style takes over, and you can see it's now centered, the images are completely flush with the bottom, and the background color has been applied. Now let's set an ID for the cell containing the teacloud logo. I'm going to click inside there. I'm going to click to select the entire cell.

And this is another way to set an ID. I'm going to come over here and open up my Tag Inspector. The Tag Inspector lets you see and edit all the attributes of a particular XHTML tag. Since there is no way to assign an ID to table cell from the Property inspector, notice we don't have an ID field here, like we did for the entire table, we can do this from the Tag Inspector. And I'm going to make sure the Attributes tab is selected here. I'm going to look under CSS/Accessibility. And in here, I can find an id field. And here's where I can add the actual ID for that cell. I'm going to type tdLogo, for table cell, and logo, because it's the cell containing the logo. And that's all I need to do. That's the equivalent of when we selected the table, and added the ID here. But again, there's no way to do that for a cell.

So you can to that from the Tag Inspector here. Now I need to create the actual rule. Let's go create another rule. And in this case, I want to have the #tdLogo as my selector. Click on OK. Let's come in here to the Background area, and I want that Background color to match the logo. So I'm just going to sample that. Let's go over to the Block category. And we also want that to be centered as well. And we'll go to the Box category again. And we're going to set the width of the box to 140 pixels. That's going to force the cell to become a little bit wider. And then we'll go ahead and click on OK.

And there it is. Because we added the ID to it, and once we created the actual rule for that ID, it was automatically applied. Alright, let's take a look at one more ID that we can set. And, in this case, we're going to set the style for the sidebar over here on the right hand side. We're going to click inside this cell. Select the in the Tag Selector. And again, I need to give it an ID. So I'll come over here to my Tag Inspector, next to id. And we'll call this tdSidebar. And now I need to create a rule for the sidebar. We'll come in here and click the new rule. This will be #tdSidebar. Click on OK. And let's go to the Background field again. Background color we're going to use in this case is going to be #E3E5DC.

Now, I also have a Background image that I'm going to use here. So I'm going to Browse for background image. And under assets > Images > navigation, I have a file in here called sidebarbackground.gif, which we can see just looks like a faded bamboo image, which we're going to use for our background. So I'm going to select that. And I want to set up some properties for this image. I'm going to choose no-repeat from the Repeat pop-up menu, meaning that I don't want this background image to tile. I only want this image to appear once in the background of the cell. For the Vertical position, I'm going to choose bottom, meaning I want it to be lined up to the bottom of the cell. Now let's go over to the Block category. Under Vertical alignment, I'm going to choose top. This means that the content of the cell, not the background image I was working with, but in this case, these links, the content is going to be aligned to the top of that cell.

And let's click on OK and see what happens. And there it is, there is the image that I added. It looks like a nice little bit of bamboo there, and my links have been shoved to the top of the cell, because I said the vertical alignment for this particular cell should be at the top. Let's go ahead and save our changes to both our style sheet and our page. Let's take a look in our browser. Let me refresh this page. There it is. So this page is starting to look pretty good at this point. All of the table cells are properly styled using a minimum of CSS rules. So giving each of the table cells its own ID ensures that they're the only table cells that are affected by the new styles. So if I want to apply styles to other tables later on, I don't have to worry about the cells and those other tables being affected by the styles that I created with these IDs.

Let's go back to {italic}Dreamweaver.{plain} So, those are ID selectors. So, so far we've cover text and ID selectors. In the next movie we'll look at class selectors.

Show transcript

This video is part of

Image for Dreamweaver CS3 Essential Training
Dreamweaver CS3 Essential Training

129 video lessons · 86980 viewers

Garrick Chow
Author

 
Expand all | Collapse all
  1. 1m 12s
    1. Welcome
      1m 12s
  2. 21m 0s
    1. HTML vs. XHTML
      3m 4s
    2. What is CSS?
      3m 48s
    3. What is XML?
      2m 11s
    4. What is DHTML?
      1m 9s
    5. What is JavaScript?
      1m 23s
    6. File naming conventions
      3m 22s
    7. What is an index page?
      6m 3s
  3. 46m 18s
    1. Setting up your workspace
      2m 39s
    2. The Welcome screen
      4m 11s
    3. Windows and Mac differences
      3m 18s
    4. The Insert bar
      4m 38s
    5. The Property Inspector
      1m 50s
    6. The Document toolbar
      6m 6s
    7. The Document window
      9m 11s
    8. Panels and panel groups
      6m 58s
    9. Saving workspace layouts
      2m 22s
    10. Defining a default browser
      5m 5s
  4. 24m 59s
    1. Defining a site
      9m 5s
    2. File and folder management
      3m 11s
    3. Understanding path structure
      3m 17s
    4. Adding content to a site
      6m 6s
    5. Creating a site map
      3m 20s
  5. 38m 39s
    1. Creating a new blank site
      6m 0s
    2. Creating and saving a new document
      7m 54s
    3. About DOCTYPE
      3m 59s
    4. Inserting images
      9m 26s
    5. Inserting text
      3m 35s
    6. Aligning text and images
      4m 9s
    7. Inserting meta tags
      3m 36s
  6. 45m 58s
    1. Link basics
      6m 4s
    2. Linking with Point to File
      5m 18s
    3. External links
      4m 15s
    4. Creating email links
      5m 49s
    5. Named anchors
      7m 37s
    6. Linking to a file
      7m 35s
    7. Image maps
      9m 20s
  7. 1h 8m
    1. About CSS
      4m 52s
    2. Anatomy of a style sheet
      4m 10s
    3. CSS and page properties
      10m 11s
    4. Moving an internal style sheet to an external style sheet
      6m 46s
    5. The CSS Styles panel
      3m 48s
    6. CSS selectors
      2m 37s
    7. Type selectors
      12m 13s
    8. ID selectors
      10m 21s
    9. Class selectors
      5m 42s
    10. Creating rollovers with pseudo-class selectors
      7m 22s
  8. 42m 54s
    1. CSS vs. the Font tag
      2m 42s
    2. Formatting text with the Property Inspector
      8m 41s
    3. What measurement should I use?
      3m 15s
    4. Managing white space with margins, padding, and line height
      8m 34s
    5. Using font lists
      5m 45s
    6. Aligning text
      2m 47s
    7. Creating lists
      5m 8s
    8. Creating Flash text
      6m 2s
  9. 43m 19s
    1. About tables
      1m 28s
    2. Tables in Code view
      2m 36s
    3. Creating and adding content to tables
      7m 40s
    4. Changing table borders with XHTML
      5m 46s
    5. Coloring tables with XHTML and CSS
      6m 41s
    6. Aligning table content
      6m 39s
    7. Sorting tables
      3m 6s
    8. Setting table widths
      4m 48s
    9. Creating rounded-corner tables
      4m 35s
  10. 28m 22s
    1. Dreamweaver's layout tools
      3m 8s
    2. Tracing images
      4m 58s
    3. Adding AP div tags
      7m 29s
    4. Working with Layout Tables
      6m 55s
    5. Adjusting table widths and nesting tables
      5m 52s
  11. 16m 19s
    1. What is a device?
      3m 14s
    2. Attaching a printer-friendly style sheet
      3m 5s
    3. Styling for print
      7m 41s
    4. Adobe Device Central
      2m 19s
  12. 29m 54s
    1. Rollover rules
      3m 31s
    2. Creating simple rollovers
      5m 36s
    3. Creating disjointed rollovers
      7m 12s
    4. Creating navigation bars with multiple states
      9m 21s
    5. Creating Flash buttons
      4m 14s
  13. 26m 32s
    1. Viewing the code
      6m 9s
    2. Editing in Code view
      3m 0s
    3. The Code toolbar
      5m 11s
    4. Working with Code Collapse
      4m 27s
    5. The Quick Tag Editor
      2m 20s
    6. Working with snippets
      5m 25s
  14. 32m 45s
    1. About forms
      3m 23s
    2. Adding text fields
      9m 52s
    3. Adding checkboxes and radio buttons
      5m 37s
    4. Adding lists and menus
      6m 5s
    5. Submitting form results
      3m 23s
    6. Styling form elements with CSS
      4m 25s
  15. 23m 17s
    1. Opening a new browser window
      9m 38s
    2. Creating a popup message
      2m 50s
    3. Validating text fields
      2m 42s
    4. Getting more behaviors
      7m 2s
    5. Removing extensions
      1m 5s
  16. 14m 58s
    1. External image editor preferences
      3m 18s
    2. Built-in image editing tools
      3m 11s
    3. Roundtrip editing from Dreamweaver to Fireworks or Photoshop
      4m 39s
    4. Copying and pasting
      3m 50s
  17. 34m 16s
    1. Templates in action
      5m 12s
    2. Creating a new template
      6m 36s
    3. Applying templates
      3m 36s
    4. Modifying a template
      1m 40s
    5. Adding repeating regions
      3m 28s
    6. Working with repeating regions
      3m 13s
    7. Adding optional regions
      3m 34s
    8. Creating a library item
      3m 48s
    9. Modifying a library item
      3m 9s
  18. 13m 2s
    1. Using the History panel
      4m 24s
    2. Saving History steps as commands
      3m 25s
    3. Using Find and Replace
      5m 13s
  19. 14m 44s
    1. W3C accessibility guidelines
      4m 6s
    2. Accessibility preferences
      1m 29s
    3. Inserting accessible images
      3m 2s
    4. Inserting accessible tables
      2m 53s
    5. Inserting accessible form objects
      3m 14s
  20. 26m 17s
    1. About media objects
      2m 6s
    2. Linking to audio and video files
      5m 56s
    3. Embedding audio and video files
      7m 7s
    4. Setting parameters
      4m 27s
    5. Inserting Flash content
      2m 37s
    6. Inserting Flash video
      4m 4s
  21. 28m 47s
    1. Getting site reports
      3m 35s
    2. Checking links sitewide
      3m 30s
    3. Signing up with Tripod
      6m 36s
    4. Entering remote info
      4m 13s
    5. Publishing your site
      5m 41s
    6. Updating and publishing pages
      5m 12s
  22. 44s
    1. Goodbye
      44s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now "Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Dreamweaver CS3 Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

  • new course releases
  • newsletter
  • general communications
  • special notices

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

  • new course releases
  • newsletter
  • general communications
  • special notices

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.