Creating a YUI TabView Style Theme for the AjaxControlToolkit's TabContainer Control
I was browsing the YUI documentation and I came across a very nice looking tab control. I thought it would be interesting to create a similar styled theme for the AjaxControlToolkit's TabContainer control. I don't mind the default XP-themed TabContainer, but I think the XP style tab's are getting a little bit dated. I had not previously created a theme for a TabContainer, so I had no idea what to expect. It turns out it was very easy to do. Below are the steps I followed ...
[Update 10/1/2007] :
- Updated CSS so it would work with IE6
- Check out here for additional TabContainer theme
- Check out here for an XP without the roll-over flicker
Read the 'Tab Theming' Section of the TabContainer's Documentation
Because I haven't created a custom theme for this control yet, I needed to do a little research before getting started. I read through the paragraph on the toolkit's sample site that explains how the TabContainer control can be themed. It turns out theming is pretty simple - it boils down to understanding which HTML element's the following 7 css classes are applied to*.
* Be careful, I think there is a small bug in this documentation. The documentation for the .ajax__tab_outer class states that it is often used to set to left-side background image of the tab. I think .ajax__tab_outer is used to set the right-hand side image while .ajax__tab_inner is used to set the left-hand image. Check out the XP themed css for these classes. Notice the tab_outer class is assigned the tab-right image and the tab-left is assigned to the tab_inner class. Also notice how the images are aligned.
.ajax__tab_xp .ajax__tab_outer
{
padding-right:4px;
background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-right.gif")%>) no-repeat right;
height:21px;
}
.ajax__tab_xp .ajax__tab_inner
{
padding-left:3px;
background:url(<%=WebResource("AjaxControlToolkit.Tabs.tab-left.gif")%>) no-repeat;
}
Use the IE Developer Toolbar to View the XP Themed TabContianer's HTML Elements
Next, I used the IE Developer Toolbar so I could see how these classes are used for styling by the default XP theme. If you haven't used the toolbar, I highly recommend checking it out. It is one of those tools where once you start using it you wonder how you ever got along without it. Below are screen shots of a very simple tab control that uses the default XP style theme. In each figure, the area shaded in blue is the element the corresponding css class is assigned to.
Use the IE Developer Toolbar to get the Color Codes and Image's from Yahoo's Demo Site
After I completed my research on how theming works with the TabContainer, I started the task of figuring out what style attributes are used on Yahoo!'s YUI TabView demo page. Again, I used the IE Developer Toolbar to drill into the various DOM Elements so I could get the exact hex-codes for various colors and images used by the control. Below is a screen shot of the toolbar tool. On the left pane is a review that displays the DOM for the page being viewed. The right pane displays the values of all of the style attributes for the selected element.
Create the YUI TabView CSS Classes
Now that I have determined which style attributes I need, I can start creating the stylesheet using the well known TabContainer classes described above. According to the TabContainer's theme documentation, the style classes need to be prefixed with the css class that corresponds to our custom theme. This way, the TabContainer can be themed by setting the value of the CssClass property to the name of our custom theme. So for our example, we will define the above mentioned classes under the .ajax__tab_yuitabview-theme class like so ...
/* ajax__tab_yuitabview-theme theme (img/yui/sprite.png) */
.ajax__tab_yuitabview-theme .ajax__tab_header
{
font-family:arial,helvetica,clean,sans-serif;
font-size:small;
border-bottom:solid 5px #2647a0;
}
.ajax__tab_yuitabview-theme .ajax__tab_header .ajax__tab_outer
{
background:url(img/yui/sprite.png) #d8d8d8 repeat-x;
margin:0px 0.16em 0px 0px;
padding:1px 0px 1px 0px;
vertical-align:bottom;
border:solid 1px #a3a3a3;
border-bottom-width:0px;
}
.ajax__tab_yuitabview-theme .ajax__tab_header .ajax__tab_tab
{
color:#000;
padding:0.35em 0.75em;
margin-right:0.01em;
}
.ajax__tab_yuitabview-theme .ajax__tab_hover .ajax__tab_outer
{
background: url(img/yui/sprite.png) #bfdaff repeat-x left -1300px;
}
.ajax__tab_yuitabview-theme .ajax__tab_active .ajax__tab_tab
{
color:#fff;
}
.ajax__tab_yuitabview-theme .ajax__tab_active .ajax__tab_outer
{
background:url(img/yui/sprite.png) #2647a0 repeat-x left -1400px;
}
.ajax__tab_yuitabview-theme .ajax__tab_body
{
font-family:verdana,tahoma,helvetica;
font-size:10pt;
padding:0.25em 0.5em;
background-color:#edf5ff;
border:solid 1px #808080;
border-top-width:0px;
}
Update your TabContainer's to use the Theme
After the classes for the theme have been defined, they can easily be applied to the TabContainer by setting the CssClass attribute of the control to the name of the theme like so ...
<ajaxToolkit:TabContainer runat="server" CssClass="ajax__tab_yuitabview-theme" />
That's it. Enjoy!
Comments
excelent !!!
Thanks for sharing! I have tried this myself in the past, but the use of the IE Developer Toolbar as you've outlined makes this easier than ever to accomplish.
Please notice there is a small typo in your post ("contianer") in the heading Use the IE Developer Toolbar to View the XP Themed TabContianer's HTML Elements.
@Peter
I appreciate the feedback and good catch on the type-o. I am terrible at spelling!
Matt
Thanks Matt,
I just don't quite get how the CSS is able to extract the different (background) images from a single sprite.png file.
I've googled for this, but that didn't help me much. Can you point us to a direction where this is further explained? This would give me the perfect opportunity to clean up my /images folder on the various themes of a project...
Thanks again,
Peter.
The tabs did not work in IE6 for me. Is this just a problem on my end?
Thanks Matt!
This looks great, but I'm having trouble running it on my machine. The default XP skin shows up fine, but the YUI skin doesn't. The first tab (Opera) takes up the entire width of the tabcontainer and I have to scroll way to the right to find the next tab. Any ideas?
@Peter
Try this link (http://www.alistapart.com/articles/sprites) for learning more about this technique.
Thanks,
Matt
@John
I am not sure. Is anyone else seeing this problem?
Thanks,
Matt
@Alan
Have you made any changes to the download? If so, send me the code (matt@mattberseth.com) and I will take a look at it.
Does the sample page hosted on mattberseth2.com render properly?
Thanks,
Matt
I'm using the Yahoo! version and it looks/works great with IE7, but with IE6, each tab header takes up the width of the entire screen. I noticed another person complaining about IE6, but I'm not sure if it's the same problem.
Matt,
Thanks for the followup. I tested the demo on mattberseth2. It displays just fine on Firefox but not on IE6. It's the same error I mentioned earlier. The first tab takes up the whole width of the tabcontainer with the other tabs off to the right. I would be happy to email you a screenshot if that would help. Thanks so much!!
@Alan, @Ali, @John
I was also able to reproduce this problem using IE6. There was a bug in the stylesheet that I believe has been fixed. I will publish the changes I made later on today. Please let me know if you are still having problems in IE6 ...
Matt.
Matt,
Have you had a chance to publish the update?
Thanks,
Ali
@Ali -
Sorry, I had forgot. It should be updated now. Let me know if you have any other issues.
Matt.
Hi there,
I am trying to implment the same thing however the css gets really messed up when u have tab inside of a tab?
I have main tab which is using xps however my inner one is using yahoo styles as u showed. Have u encountered any problems in relation to that?
Matt,
Did you upload the CSS? I'm getting the IE6 bug with the yahoo theme.
Thanks.
Great post.
@Charlie -
I reapplied the css to the zip file and re-uploaded. Please let me know if you are still having issues.
Matt
@Charlie -
I reapplied the css to the zip file and re-uploaded. Please let me know if you are still having issues.
Matt
Hi, Matt,
I found that your article is very easy to read, yet contains a lot of good information that I can apply in my job. Thanks a lot. When I run your code, I notice that the left border of the first tab(Opera) is not showing up when the tab is selected. Do you have a fix for this ?
Mansion
Nice tab style! However, I'm having trouble with the YUI tab style in FireFox. The Tabs are floating above the tab body. It's strange because they flow outside of ajax__tab_header. They don't seem to be obeying the vertical-align bottom and instead float to the top of the tab header. Has anyone else seen this? Another peculiar thing is that it doesn't happen on all of the tab instances in my app, only some of them. I'll keep digging, to see why, but I thought I'd post to see if anyone else has seen some flakiness under FireFox. --Thanks!
Well...The tabs are aligning properly now, but I hate solutions like this that I don't understand! It's working but I can't explain why.
What I did was put an explicit hight on the tab header, and change the vertical-align to baseline instead of bottom.
/* ajax__tab_yuitabview-theme theme (Images/sprite.png) */
.ajax__tab_yuitabview-theme .ajax__tab_header
{
:
height:28px;
}
.ajax__tab_yuitabview-theme .ajax__tab_header .ajax__tab_outer
{
:
vertical-align:baseline;
:
}
Those are the only two changes I made. It seems to work in IE6, IE7, FF and Safari.
hi, is there is any way we can show drop down menu also on tab.
thanks
In my asp.net application theme for CheckBox set properly for Explorer but not set for Firefox. what changes i have to do in CSS file? Plz Give me solution for it..
Thans very much, great work.
Thansk, very much!
Very great!