Sliding Doors of CSS

by Douglas Bowman

131 Reader Comments

Back to the Article
  1. Very nice article, explains very well the possibilities of using mutiple background images, in a “layered” kind of way. Well done!

    Copy & paste the code below to embed this comment.
  2. Interesting article, without a doubt, but it seems to ignore IE6—why’s that?

    And there’s no mention that only the text is clickable in IE6 (not rest of the tab). Is there a fix for this? Most of the tabs I see people using, both image-based and CSS ones make the whole image area interactive.

    Copy & paste the code below to embed this comment.
  3. i’m happy to let IE6 users go through the ever so slightly steep learning curve required to click on the link rather than the tab.

    this is fine because the site i am using this on is a personal one, but in a business environment this may be a factor that would have to be seriously thought over.

    other than that, an excellent piece of coding.

    welcome back ala!

    oh btw nice hack from Tobias for rollovers. i’ve used it :)

    Copy & paste the code below to embed this comment.
  4. This has achived an effect that i was trying to achive myself and got wrong in oh so many small ways.
    Its a lovely pice of work

    My own attempts sucumbed to horrible nasty hacks and gettarounds.

    This if very nice and much more tidy than my own implementation.

    Thank you its great to find such helpfull articles.

    Copy & paste the code below to embed this comment.
  5. I’m a 19 italian student and I love CSS design. This article is really cool ‘cause now I’ve got new tools for my design.

    Bye bye from Piero, Italy.

    Copy & paste the code below to embed this comment.
  6. <<Having ‘every visit to the page’ selected in IE really is a showstopper.. i’m wondering if the default setting is ‘never’?>>

    After getting two new computers in the same week, I can report that the default setting for IE6 in WinXP is “Automatically”—which produces no flicker.

    Only Web developers, motivated by the lust to view their latest changes, would think to change this setting to break the cached behavior.

    Copy & paste the code below to embed this comment.
  7. Nice work, I’ll get to sliding.

    Copy & paste the code below to embed this comment.
  8. I’m so happy to have A List A Part back.  Articles like this make many of us wish we could “:hover” over your shoulders for a day—gleaming as much as we could.  Thanks for all you offer.

    Copy & paste the code below to embed this comment.
  9. I also had that problem. For me it works fine when using a title-tag for the links. Problem fixed. :)

    Copy & paste the code below to embed this comment.
  10. Great solution, Markus… :thumbsup:

    Copy & paste the code below to embed this comment.
  11. Have tried in IE6, Firebird 0.7 and Opera 7 and I could not get images for the tabs, except for version 1 in Opera 7, which gives me the inactive tabs fine, but the active tab is not complete. Confused since everyone else says this rocks, and it sounds great….update – just refreshed my firebird and now it gives a working version 1, but still with broken active tab. You must be working on it…will check back. Cheers.

    Copy & paste the code below to embed this comment.
  12. I’m with everyone else in heaping praise on this article and technique, I just want to ask a question though about the behaviour of the tabs when the window width is less than the total width of all five tabs.

    Using both IE6 and Firebird 0.61, examples 1 and 2 in the article make the tabs line up to the left, so if the window is only wide enough to fit in the Home, News and Products tab then the About and Contact tabs are aligned to the left on the next line. With examples 3 onwards the About tab displays directly below the Products tab and the Contact tab displays on a third line.

    This isn’t so much a criticism as just an enquiry as to why this happens. I don’t know enough about CSS to work it out for myself unfortunately.

    Copy & paste the code below to embed this comment.
  13. I am going to try right align the tabs.  Has anyone tried that?

    Copy & paste the code below to embed this comment.
  14. dear people, tabs are so last millenium.  CSS is a silly hack.  Don’t use tables because they are obsolete (as if the browser will EVER stop recognizing tables.  wake up!), yet use an UGLY hack to make this stuff work. Extraordinary.

    Copy & paste the code below to embed this comment.
  15. to sandro:

    If tabs are the right interface that is a great discussion. I don’t know if they are soooo last millenium, but I’m not convinced I like them either.

    But saying CSS is nothing but an ugly hack and tables the best layout medium means either you are trolling around here (in which case your post better be deleted) or you show an extraordinary ignorance that is exemplarary of too many webguys who know one little trick and think that’s the ultimate way of working. Read http://www.macromedia.com/newsletters/edge/october2003/index.html?sectionIndex=1&trackingid=OMN_AAJT to start with.

    Copy & paste the code below to embed this comment.
  16. to martijn:

    css is often hacked.  the css in this example has a very prominent hack.  other examples have other hacks.  if you want to call that a troll, well…

    tables are the best layout medium.  they are easy and known and automatically reflow.  they will never disappear, you can quote me on that.  they should be part of the standard, and any body that seeks to destroy something that is known and useful simply to conform to an abstraction like ‘standards’ is someone not to be trusted.  which is most likely to happen? css hacks suddenly fail one day on a new browser release? tables stop being supported, thereby neutering, guessing, 10 billion websites or so?  i wonder why amazon continues to use tables for their tabs.  must be one trick ponies.

    You can go to uspto.gov and do a search for sandro pasquali.  read through my patents.  You will see in my work a commitment to advanced dynamism in websites. 

    It is amazing that you send be to a 300 k flash file so i can read a 3 column layout (hint: everyone knows that’s the wrong way to present text on the web) that celebrates css. there’s so much humor there i’ll just leave it for posterity.

    look, knock yourself out.  use css if you like.  i often use it for setting fonts and so on.  but i offer that there is more power is learning javascript and manipulating the dom directly, via attributes, and even more power if you have the knowledge and desire to build XUL-ish layout manifests and have those parsed by a javascript-driven xml/http loader and local parser.  you see, this lets you write functions that determine style attributes based on modal concerns, instead of dumb css templates that, let’s hope!, get attached to the right documents.  if you never want to progress beyond being a blog styler, stay with css. it’s easy and fun.

    Copy & paste the code below to embed this comment.
  17. sandro pasquali said:

    >>“You can go to uspto.gov and do a search for sandro pasquali.”

    The search for sandro pasquali:

    http://www.firstgov.gov/fgsearch/index.jsp?fr=0&nr=20&de=detailed&mw0=sandro pasquali&mt0=phrase&ms0=must&in0=domain&dom0=www.uspto.gov&db=www&rn=1&parsed=true&act;.search=Submit

    The result:

    Your search did not return any documents. Please revise your search and try again.

    Copy & paste the code below to embed this comment.
  18. To those people who earlier inquired about centering the tabs: I can’t think of a way to do it without putting a wrapper <div> around the entire block of Doug Bowman’s HTML code, and without specifying an exact width for at least one of the <div>‘s involved. If I’m wrong, someone please correct me; I’d really like there to be a simpler way to do this using CSS.

    The HTML would look something like
    <div id=“header-outerwrap”>
      <div id=“header-innerwrap”>
      <div id=“header”>
        <ul>
          ….
        </ul>
      </div>
      </div>
    </div>

    And the CSS would be something like

    #header-outerwrap {
      text-align:center;
    }

    #header-innerwrap {
      margin:0 auto 0 auto;
      text-align:left;
      text-align:center;
      width:XXXpx;
    }

    #header {
      /*Bowman’s styles */
    }

    Two wrapper <div>‘s are needed because
    1. The original header <div> has been
      left-floated, and therefore needs at least
      one containing <div> to which centering can
      be applied.
    2. IE/Win 5.X has a bug that causes elements
      with left and right margins of “auto” to
      not display as centered. To work around
      this, an extra div is needed…this
      centering hack is explained elsewhere
      online; do a google search if you don’t
      know it already.

    I have only tested the above code in IE6/Win2K and FB0.7/Win2K; it works fine on both.

    Copy & paste the code below to embed this comment.
  19. Note that this technique doesn’t center the actual tabs; instead, it centers the div that the tabs are in. I haven’t figured out how to center the tabs themselves; since they are left-floated, center-alignment is problematic.

    Copy & paste the code below to embed this comment.
  20. It would be fine to click the whole tab not just the text link.

    Copy & paste the code below to embed this comment.
  21. I have read the number of great responses to this article, but for some reason I am not having the same luck.  for some reason the CCS code below does not render so that the current tab is diplayed with both rounded edges.
      #header #current {
      background-image:url(‘images/norm_right_on.gif’);
      }
      #header #current a {
      background-image:url(‘images/norm_left_on.gif’);
      }

    If I change it so that the CSS is:
      #header #current {
      background:url(‘images/norm_right_on.gif’) no-repeat right top;
      }
      #header #current a {
      background:url(‘images/norm_left_on.gif’) no-repeat left top;
    the right side is rounded but not the left.  Anything to help out!
      }

    Copy & paste the code below to embed this comment.
  22. > Clicking the whole tab… | martin:

    > It would be fine to click the whole tab not
    > just the text link.

    2nd that.

    Unfortunately, there still seems to be this strong trend among Web Standards Evangelists and Devs to ignore popular browsers—to focus their efforts on browsers with cooler names and OSes like Zeldzilla, Macintush, Firequeror, Funix, Surfari, Limex, etc. Browsers with old-school, pedestrian names like Internet Explorer and Netscape Navigator (sheesh, how could they come up with anything more lame than those???) are pretty much ignored when they’re running on something as sad as Windows 2000 (three years out of date, to be sure!) or XP (NT clone? outta here! :P ).

    Screen readers are cool though. Just ask your 95% lame-o user base that’s still doggedly using IE5/6 for Win to go poke their eyes out and learn Braille. That’s the way to do it. Chix fer free! You might even get on MTV

    Copy & paste the code below to embed this comment.
  23. Thank you so much Mr. Bowman (and ALA) for shedding some light onto an issue that I have worked on (without much success) for some years now. I have always loved the power of CSS and its’ ability to separate design from content, but there were definitely some roadblocks when using it to try something of this nature.

    Thank you again for sharing your discovery. I was so proud of myself when I discovered how to use CSS to display a list inline. Now, I am truly humbled… :)

    p.s. It is good to see you back in action ALA! I have sorely missed you all this time.

    Copy & paste the code below to embed this comment.
  24. I tried using these tabs with (my first!) dw mx database driven site: the tab texts and page contents are all pulled from a flat database. Looks great, works too. (got php to drive the span tag too.)

    Now trying second level menu: this is where the ‘tab’ metaphor really breaks down of course.

    So for the second level menu: how to get the top level menu to stay in the selected state? A little database-puzzle.

    Copy & paste the code below to embed this comment.
  25. The unclickable part on the left of the tab can become clickable an alternate way.
    Leave everything the way it was just before the “Finishing Touches” section.

    Now add a “margin-right: 3px;” to the “#header li” style and a counter “margin-left: -3px;” to the “#header a” style.

    i.e.

    #header li {
    float: left;
    background: url(“right.gif”) no-repeat top right;
    margin-right: 3px;
    padding: 0;
    }

    #header a {
    display: block;
    background: url(“left.gif”) no-repeat top left;
    padding: 5px 15px 4px;
    margin-left: -3px;
    }

    Unfortunately works only in Opera (at least v7).
    Don’t know if it works with IE/Mac

    Copy & paste the code below to embed this comment.
  26. See Sliding Doors of CSS II, published 30 October in Issue 161, for IE-oriented workarounds, rollovers, and more:

    http://www.alistapart.com/articles/slidingdoors2/

    These Sliding Doors extensions, exceptions, and workarounds were omitted from the initial article to keep the focus on the concept and execution of this new CSS design method. The initial article was complex enough! Additional complexities, we felt, belonged in a follow-up article, and we are happy to now publish that follow-up.

    Copy & paste the code below to embed this comment.
  27. Call me an idiot, but I can’t seem to get the “right.gif” image.  I suppose I could make my own, but was trying to get your example to work first, before I tried anything else.  Can you send or provide a location?

    Copy & paste the code below to embed this comment.
  28. I had just been trying to build a box with rounded corners when I read the article. Inspired by it, this is what came of it: background-images (e.g. rounded ones) on all four sides and completely stylable background surface

    http://www.andreas-kalt.de/roundedbox/index.htm

    Andreas

    Copy & paste the code below to embed this comment.
  29. Last night I was lying in bed thinking, “I wish CSS gave me a way to put one image in the upper right corner of a link and a different one in the upper left corner…”

    Today I discover that it does! Thanks for a brilliant demo.

    Copy & paste the code below to embed this comment.
  30. I get the flickering behavior on IE6 on win2k regardless of my browsers cache setting (ie “Check for new version of page” on Auto).

    In fact, that setting doesn’t seem to have any effect at all on this computer (e.g. there seems to be no cache-ing).  It seems like rollovers, etc always reload when moused over, etc.  This results in slightly less responsive rollovers and is annoying.

    Anyone else notice this lack of cacheing on IE6 on win2k?

    Copy & paste the code below to embed this comment.
  31. Up to now I used this technique without CSS. You’ve made it much easier now. Thank you!

    Copy & paste the code below to embed this comment.
  32. Great technique, but I have experienced some problems positioning the tabs. When using absolute positioning, this can work in Mozilla/IE , but Opera 6(win) has problems. Relative positioning works in Opera, but this dies a sad death in IE.

    If anyone has perfected positioning the 2 floats , I would be very grateful for a few pointers!!

    Copy & paste the code below to embed this comment.
  33. For some reason, when I open my page in netscape, it doesn’t break between the final </div> and the procedding code.

    That tabs are there and working fine, but then my stuff is to the right of them, as opposed to under them.

    Copy & paste the code below to embed this comment.
  34. I am having a problem with a site, http://www.wfmuziek.nl, which seems to be caused by the same thing as the IE/Mac CSS rendering problem.

    I don’t have a Mac to test on, but a Mac sent me a screenshot… there’s a huge gap where the content div should be, and you have to scroll all the way to the right to see the content.

    Is there a Mac user who wants to take a look at the site’s CSS and suggest what might be causing this?

    Copy & paste the code below to embed this comment.
  35. It included the comma in the link, so here is is again:

    http://www.wfmuziek.nl

    Copy & paste the code below to embed this comment.
  36. For those of you looking for more positioning control (i.e. centering your tabs, etc), don’t forget that this technique can be easily adapted to a table-based layout. Simply style the <td> tag instead of the <li>.

    I know it’s not perfect, but if your business/design requirements make a CSS-based layout impractical, it’s a nice compromise.

    Copy & paste the code below to embed this comment.
  37. I implemented tabs similar to these, but the background images kept flickering in IE6. After much head-scratching, I copied your example verbatim up to my web server, and the problem still occured. It turns out that IE6 won’t cache images when the web server sends them gzipped (which Apache often does). Since your sliding doors are hosted on IIS which doesn’t use gzip content-encoding, there is no problem for you.

    Copy & paste the code below to embed this comment.
  38. In my previous post I mentioned the IE6 content-type:gzip bug. If you’re on a Linux/Apache system that uses mod_gzip, you’ll need to disable it to avoid constant image reloads in IE6. My host is crediblehost.com, and I created this .htaccess file at my public_html root:

    <ifmodule mod_gzip.c>
    mod_gzip_on no
    </ifmodule>

    Which did the trick.

    Copy & paste the code below to embed this comment.
  39. This is why I missed you guys. :)

    Copy & paste the code below to embed this comment.
  40. As I just commented on the follow up article, there’s no need to split the tab images into left and right.  The background alignment allows a single image to be used.  See this at http://www.alzonline.net/en/forums/

    Copy & paste the code below to embed this comment.
  41. Hi,
      The article is wonderful and I implemented this in my current project. One of my screens has lot of tabs and they wrap around to the next line. I am using this inside one of the frames. The frame doesn’t have the scrolling=“no” , so how to make the tabs without wrapping to the next line.

    thanks in advance,
    Krishna

    Copy & paste the code below to embed this comment.
  42. Excellent article, and it gave me an idea.

    What if you have one DIV container that is transparent (DIV1), and inside that DIV is another DIV (DIV2) that is colored, and has the link text in it. DIV2 is centered horizontally and vertically in DIV1.

    Now, use your sliding doors technique, but instead of a regular graphic, you create a graphic that has the rounded-edge look that fades to transparency. The region between the inside edge of DIV2 and the outside edge of DIV1 would be filled with the graphic, which would fade to transparency at the junction between DIV1 and DIV2.

    What does this accomplish? Well, you have the rounded ‘graphic’ look, but you can change the color of DIV2. Hence, you can use CSS to change the color of the ‘button’ (DIV2) at will, and since DIV1 is transparent, you won’t see the little corners of color at the outside corners of DIV1, where the graphic is transparent.

    Copy & paste the code below to embed this comment.
  43. This is really awesome!  Didn’t know this was all possible with ‘simple’ CSS.
    You really showed me the power of CSS.  I’m convinced more than ever about the capabilities of CSS.

    Thanks for this great example!

    Rgds,

    Geert

    Copy & paste the code below to embed this comment.
  44. Yesterday, I reported Japanese character wrapping within a tab. 
    After that I noticed that the same symptom happens for alphabetic words.
    For verification, I changed tab wording from single word to two words, such as New York, New Jersy, and so on.
    If you make browser’s width narrower ‘New’ and ‘York’ are formatted in two lines.

    I prefer to have a fix for this issue.

    Copy & paste the code below to embed this comment.
  45. include a non-breaking space rather than a ” ” in menu items that have 2 or more words.

    Copy & paste the code below to embed this comment.
  46. This was a wonderful article and I love the technique used here. It has made my work so much easier. I have tried using the same technique with a vertical menu but without much success. Has anyone out there accomplished this?

    Copy & paste the code below to embed this comment.
  47. Thats given me some good ideas… thanks for taking the time out.

    Copy & paste the code below to embed this comment.
  48. Please excuse my total ignorance.

    I’m redesigning an old table-based page with a lot of tabs along the top (ie “news | gallery | store | contact” etc). Since this navbar is a repeating element that gets reused in plenty of pages, what’s the best strategy for structuring the site? My current options seem to be:

    1) paste in the tab markup by hand into each page

    2) use a SSI to reference a “nav.shtml” file
    (pro: if i use this method I can script nav.shtml so the current page’s tab is highlighted or “greyed out”
    con: the scripted “nav.shtml” is pretty hefty)

    3) use the <object> tag to reference “nav.html”
    (do other designers use this tag a lot?)

    I just want to have tabs that I can easily update 6 months from now without editing a million html pages.

    Copy & paste the code below to embed this comment.
  49. Hi,
    great css…I had one problem though..I couldn’t get the little white corners to disappear….: (  I followed along everything was going great..I added the css to my file ..to remove them….but they remained ….I use IE 6 I dunno if that matters ….other than that it worked Great …Im sure it’s probably something I’ve overlooked….but I tried 3 times & I’m stumped…any help would be great…Thanks

    Copy & paste the code below to embed this comment.
  50. Thank you Doug for sharing this great idea with us. These tabs are fantastic and so useful!

    One minor note: Netscape 6 on the Mac has a problem with the #header containing div collapsing rather than containing the floats. The result is the background image does not appear behind the floated links. I think it may be because unlike most browsers, NN6mac doesn’t follow the CSS 2.1 specs on expanding to contain child floats. (It still follows the older CSS2.0 specs). And so, the only solution I could think of would be to put a clearing div in the html as the last element in the #header div. This of course adds clutter to the html code and is therefore probably not worth it, given the few percentage of people using Netscape 6 on the Mac.

    Has anyone else noticed this too?

    I noticed this issue in Netscape 6.2.3 on a Mac running OS9.

    Nice work Doug!

    Copy & paste the code below to embed this comment.
  51. This is really a cool feature and I was about to use it on the redesign of our new corporate site until I tested it in NS 4.7. Unfortunately our web stats show people still hitting our site with this dinosaur so we have to build for it. It’s completely broken, totally unusable in NS. Bummer :(

    Copy & paste the code below to embed this comment.