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

Using conditional comments for Internet Explorer

From: Managing CSS in Dreamweaver

Video: Using conditional comments for Internet Explorer

One of the most annoying aspects of running CSS is the annoyance of having to deal with browser incompatibility in writing hacks or alternate styles for various browsers. Although all browsers have their individual quirks, by far the worst offender is Internet Explorer. Entire Web sites are dedicated to dealing with errors in that particular browser. Now one way to deal with IE Errors are to place hacks and browser workarounds directly within your CSS. This creates messy code, makes your IE- specific workarounds harder to find and makes editing your styles even more difficult.

Using conditional comments for Internet Explorer

One of the most annoying aspects of running CSS is the annoyance of having to deal with browser incompatibility in writing hacks or alternate styles for various browsers. Although all browsers have their individual quirks, by far the worst offender is Internet Explorer. Entire Web sites are dedicated to dealing with errors in that particular browser. Now one way to deal with IE Errors are to place hacks and browser workarounds directly within your CSS. This creates messy code, makes your IE- specific workarounds harder to find and makes editing your styles even more difficult.

A better way of dealing with Internet Explorer is to place those specific styles in external style sheets, and then pass them to Explore through the use of what we call conditional comments. So here I have the tours.htm file open. And what I want to do is go ahead and just preview this page in Internet Explorer, so we can see what the issue is. So here we are in Internet Explorer, and right now everything looks fairly okay. But if I scroll down, ooh, there is a problem. Right after my tour descriptions, things just start falling apart, and they go from bad to worse.

Okay, so that's obviously not the user experience we are going for within Internet Explorer 6. So let's go see how we can fix this. So here we are, back in Dreamweaver. And I want to show you that inside the _CSS directory, I have a style sheet already written, ie6.css, and what that's doing is it's fixing a few float problems that Internet Explorer had in dealing with those tour descriptions. So a lot of times, it's trial and error. Sometimes you are going to know specific issues to Internet Explorer and kind of how to fix them.

But you notice that we are going ahead and placing them in its own style sheet, called ie6, and we are commenting those guys out. So we really don't want to pass these styles to anybody but Internet Explorer 6. Okay. I am going to go ahead and close this and go back in tours really quickly. Now what I am going to do is I am going to switch to Code View. And I am going to highlight the link tag for my main styles, and I'm a copy that. And then on this blank line just below my print style sheet, I am going to paste it. Now the reason I am doing that is because I want to import my Internet Explorer 6 styles in, and I just don't feel like typing all that out.

I am going to highlight main .css and change it to ie6. And then for media screen projection is fine. But I want to replace the title. I don't want any browser to think that these are the main styles. So I am going to get rid of that title attribute. So this is what it should read: link href _css ie6 css. And the rest of it I am just going to sort of leave from before, except for the title attribute, and we are moving that. Now I am going to save this, and if I preview this in another browser, let's say Firefox, for example, we are going to end up with some real problems.

As you can see, we started having some issues as we scroll down and these guys -- the spacing is just going all crazy. The reason that spacing is going crazy is because of the fixes that we did for Internet Explore 6. What works for ie6 is not going to work for everybody. So we only want these styles to be passed to that browser. So one of the ways to do that with Internet Explorer is through the use of conditional comments. Let me show you what I mean. Go ahead and highlight that link tag. You want the whole thing highlighted, from sort of finish. And this of course is the link tag that's dealing with ie6.

And then go over to your Snippets panel. Now this is one of the pre-built Snippets. It has nothing to do with what the snippets we created earlier in our title. I am going to go ahead and open up the Comments Snippets region. Now these are really neat. These have HTML Comments. They have CSS Comments. They have all sorts of cool stuff. I just want to expand that a little bit more so I can read these better. So notice that we have all sorts of interesting comments here, Greater Than or Equal to IE7 Conditional, IE5 Mac Comment, If IE6 Conditional, If Less Than IE8. So this is really cool.

I am going to do Less Than or Equal to IE6. So with that highlighted, I am just going to double-click Less than or Equal to IE6. You'll notice what it does is it surrounds that link tag with this, If Less Than or Equal to IE6 Conditional statement. Now every single browser in the world is going to ignore that, except for Internet Explorer. It's going to look at those conditional statements and say, ooh, you are talking to me, are you? And then it says, okay, I need to add this link. So what's going to happen now is when I save this file, if I preview that in my browser in Firefox, I notice that it don't really have any issues.

However, if I go back to Internet Explore, I am just going to scroll down a little bit, and sure enough, everything looks fine. All the spacing looks the way I needed to; everything looks really great. All right, cool. So now I am going to go back into Dreamweaver. And what I'd really like to do is go ahead and change this site-wide. It works on this page, but it doesn't work on the rest of them. And there really isn't an attached style sheet sitewide, and there is certainly not a use conditional comment sitewide. So we are going to use Find and Replace to kind of help us out with this. What I am going to do is I am going to highlight all of my link tags, starting with main.css, and going to the conditional comment, I am just going to copy them, so Ctrl+C or Command+C copy.

Then I am going to take the conditional comment and just strip it out and save my file. Now why am I doing that? Well, because I don't want it to appear on this page twice when I do my find and replace. That's why. So I am going to go up to Edit and choose Find and Replace. Here I am going to choose Entire Current Local Site, and for Replace, I am going to go ahead and paste the code that we copied earlier. So it should have both link tags and the conditional comment, and then for the Find I am going to paste it again, but this time, I am just going to delete the conditional comment.

And be sure not to hit Return or Enter with that. You want to just hit Delete or Backspace to get rid of that stuff. So now double-check what's going on here. I am looking in the Source Code. I want to replace the entire current local site. I am going to find those two link tags to the main.css and the print.css. And I am going to replace them with both of those titles, plus the ie6 down there, okay. So I'm going to go ahead and hit Replace All. It's going to warn me. It's going to say I can't undo this, are you sure? I am going to say Yes. And now it's going to go add it to this file.

You can actually see it added to the code, but look at the Search dialog box. Look how many it's added to. It's added to a bunch of them right there. That's really cool. Now I would also need to repeat this procedure by going into the subdirectories, like explorers and resources, and doing the same thing, because they are going to have a slightly different document-relative link. So they weren't found in this Find and Replace. We would need to do a specific Find and Replace for each subdirectory level. And it works just to be fine, and be a lot faster than doing it by hand. Okay, well conditional comments, these things are great. Using them for Internet Explorer- specific style sheets is going to allow you to pass all the ultimate styles necessary for Internet Explorer to function properly without having to clutter up your existing code, or worrying about other browsers being affected by the styles.

I mean, that's the best part to me is that the other browsers just ignore them. It's also a nice way of getting all of the Internet Explorer-specific styles in one place to make updating and editing them even easier.

Show transcript

This video is part of

Image for Managing CSS in Dreamweaver
Managing CSS in Dreamweaver

41 video lessons · 20821 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 4m 12s
    1. Welcome
      1m 10s
    2. Who is this course for?
      1m 5s
    3. Using the exercise files
      1m 57s
  2. 1h 21m
    1. Controlling CSS in Dreamweaver
      2m 34s
    2. Style formatting options
      4m 59s
    3. Controlling shorthand notation
      6m 9s
    4. Building a style-focused workspace
      6m 10s
    5. CSS Styles panel overview
      8m 18s
    6. The Properties Inspector
      6m 39s
    7. Creating styles visually
      11m 32s
    8. Hand-coding styles
      8m 15s
    9. Code hinting and code completion
      7m 11s
    10. Modifying styles visually
      5m 24s
    11. Using the Code Navigator
      4m 47s
    12. Using CSS Inspect
      9m 52s
  3. 1h 14m
    1. Structuring style sheets
      4m 52s
    2. Writing a style header
      2m 40s
    3. Building a color guide
      6m 5s
    4. Writing a style sheet table of contents
      8m 46s
    5. Creating sections for styles
      9m 10s
    6. Using the CSS Styles panel to organize styles
      10m 29s
    7. Resolving conflicts
      7m 3s
    8. Organizing style properties
      9m 33s
    9. Writing a CSS reset
      5m 20s
    10. Writing global classes
      3m 57s
    11. Creating a style guide
      6m 6s
  4. 1h 7m
    1. Preparing custom starter pages
      11m 32s
    2. Building custom starter pages
      10m 8s
    3. Working with code snippets
      9m 54s
    4. Writing snippets
      11m 30s
    5. Importing snippets
      6m 3s
    6. Understanding snippets libraries
      8m 11s
    7. Building a CSS framework using snippets libraries
      10m 36s
  5. 52m 15s
    1. Writing a print style sheet
      10m 3s
    2. Creating print-specific styles
      10m 45s
    3. Preparing modular styles
      4m 33s
    4. Creating modular style sheets
      7m 9s
    5. Checking browser compatibility
      6m 25s
    6. Using conditional comments for Internet Explorer
      6m 58s
    7. Optimizing CSS with Dreamweaver
      6m 22s
  6. 38s
    1. Goodbye
      38s

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
Share a link to this course

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 Managing CSS in Dreamweaver.

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:

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:

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.