First look at the HTML structure: all elements related to one tab are within one block. Now think about that for a while. This must be done by Chris Coyier's Functional CSS Tabs Revisited already, right?
Maybe. But then you may notice another thing: Chris' example uses absolute positioning for the content. This means the tabs must be of fixed height. Yet these tabs here certainly aren't!
First of all we are working with inline content here and being smart about it. We eliminate white space using the dirty but sufficient zero font-size.
There is one additional element in comparison to what Chris had:
.tab-panel element, which works as a container for the
.tab-content element. The panel is inline-block by default, which means it can take styles like overflow, position, and width and height. We set these to zero size, use
overflow: hidden; and
position: relative; so that
.tab-content disappears. For the active tab we do only one style change and it happens to the
.tab-panel element: we make it inline! Thus it no longer follows the other rules that bind inline-block. As a result it's child element will start following the flow of the next container element up in the tree.
As for the
.tab-content element it is floated and has a width of 100%. The neat thing about this combination is that it forces the element to go below the row where you can see the tab buttons.
The CSS only part of this solution works in Internet Explorer 9+. All the other browsers are supported from so far back that it is enough to tell this works on Firefox, Chrome, Safari and Opera.
<!--[if lte IE 8]> … <![endif]-->
Internet Explorer 8 and below do not support the required
.tab element gets class
checked and then we use that in CSS.
Due to redrawing issues in IE8 we avoid using selectors like + and ~ with it. And this is also the reason we set class to the
.tab element and not the radio button.
The most interesting thing with styling in IE8 and below is to keep the input element on the page: if the element is hidden using
display: none; then we never get the click events. To achieve a hidden input we position it absolutely and use IE proprietary Alpha filter to make it invisible. Then finally
z-index throws it behind so it can't be clicked. To target the element properly an additional class of
.tab-radio is added to the radio button. It is for IE8- only.
All IE8- styles are within one media query so it's easy to remove it. It is also easy to remove IE7 and IE6 only styles by following the comments.
<div class="tabs"> <div class="tab"> <input class="tab-radio" type="radio" id="tab-X" name="tab-group-Y" checked> <label class="tab-label" for="tab-X">TAB TITLE</label> <div class="tab-panel"> <div class="tab-content"> TAB CONTENT GOES HERE </div> </div> </div> </div>