I want tabs along the left side of the page instead of across the top. I'm already loading JQuery for other reasons (effects), so I prefer using JQuery to another UI framework. Searches on "vertical tabs jquery" yield links to works-in-progress.
Is getting Vertical Tabs to work across browsers fraught, or is it so trivial that, once you have a solution, it doesn't seem worthwhile to post example code?
In the following screenshot, the vertical tabs are outlined in red: http://cl.ly/image/2y0t1f1L0u00
#tab li {
cursor: pointer;
font-size: 12px;
line-height: 12px;
background: #fff;
border: 1px solid #000;
padding: 10px;
color: #fff;
font-weight: bold;
font-size: 20px;
width: 140px;
height: 130px;
padding: 0 !important;
-webkit-transform: rotate(-90deg) translate(-30px, 60px);
-moz-transform: rotate(-90deg) translate(-30px, 60px);
-ms-transform: rotate(-90deg) translate(-30px, 60px);
-o-transform: rotate(-90deg) translate(-30px, 60px);
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
}
#tab li a {
display: inline;
margin: 55px 0 0 -25px;
}
Vertical tabs are better, when you have a lot of tabs, whereas horizontal tabs, can give a quick overview of a small number of tabs.
Instead of shrinking down tab names as you open more and more tabs, vertical tabs let you see the full tab name in a cleaner list. In addition to feeling more natural, as we mentioned earlier, this allows you to click and drag your tabs from top to bottom in an order you see fit.
The first trick is to use writing-mode: vertical-lr to get the text to run vertically. By itself, the text runs top to bottom, but we want it to run bottom to top, so we spin it around it with the transform: rotate(180deg) . The default transform origin is the center of the element, so this works out great.
JSFiddle Demo (tested fine in IE8/9/10, Firefox, Chrome, Safari, Opera)
Key points
BasicImage
filter and -ms-transform
, because the rotation would be applied twice in IE9. The BasicImage
filter applies to IE8/9. -ms-transform
applies to IE9. transform
applies to IE10. Using a combination of the BasicImage
filter and transform
covers IE8/9/10.HTML
<div class="wrapper">
<ul id="tab">
<li><a href="#">One</a></li>
<li><a href="#">Two</a></li>
<li><a href="#">Three</a></li>
<li><a href="#">Four</a></li>
</ul>
</div>
CSS
.wrapper {
position: relative;
width: 488px;
}
#tab {
position: absolute;
height: 52px;
-webkit-transform-origin: 0 0;
-moz-transform-origin: 0 0;
-o-transform-origin: 0 0;
transform-origin: 0 0;
-webkit-transform: rotate(-90deg) translate(-488px, 0px);
-moz-transform: rotate(-90deg) translate(-488px, 0px);
-o-transform: rotate(-90deg) translate(-488px, 0px);
transform: rotate(-90deg) translate(-488px, 0px); /* IE10 */
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3); /* IE8/9 */
...
}
#tab li {
float: left;
width: 120px;
height: 50px;
border: 1px solid #000;
}
#tab li a {
display: block;
padding: 10px;
...
}
...
Expanding on Matt Coughlin's answer, this worked for me better, without having to hardcode lengths in pixels, so that the tabs can have variable length:
#tab {
position: absolute;
-webkit-transform-origin: 100% 0;
-moz-transform-origin: 100% 0;
-o-transform-origin: 100% 0;
transform-origin: 100% 0;
-webkit-transform: translate(-100%, 0) rotate(-90deg);
-moz-transform: translate(-100%, 0) rotate(-90deg);
-o-transform: translate(-100%, 0) rotate(-90deg);
transform: translate(-100%, 0) rotate(-90deg);
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
}
It sets the transform origin on the top right corner of the tab strip, then first translates the whole strip left by 100%, and finally performs the rotation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With