5

我想要页面左侧的标签而不是顶部的标签。由于其他原因(效果),我已经在加载 JQuery,所以我更喜欢使用 JQuery 而不是另一个 UI 框架。对“垂直标签 jquery”的搜索会产生指向正在进行中的工作的链接。

让垂直选项卡跨浏览器工作是否令人担忧,或者它是否如此微不足道,以至于一旦有了解决方案,发布示例代码似乎就不值得了?

在以下屏幕截图中,垂直选项卡以红色标出: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;
}
4

2 回答 2

11

JSFiddle Demo   (tested fine in IE8/9/10, Firefox, Chrome, Safari, Opera)

Key points

  • It's simpler to create a horizontal tab bar and rotate all of it at once, rather than rotating each tab item separately.
  • Avoid using both the 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.
  • A transformed element occupies the same space in the layout that it occupied before the transformation (the horizontal space across the width of the screen), even though it's displayed at a different location. In this version of the demo, the layout space it occupies is shown in blue. One way to avoid having this unwanted space taken up in the layout is to give the element absolute position, so that it doesn't occupy any space in the layout. Another option is to give the next element a negative top margin (to "consume" the layout space of the transformed element).

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;
    ...
}
...
于 2013-06-24T16:45:00.717 回答
3

扩展马特·考夫林的回答,这对我来说效果更好,而不必以像素为单位硬编码长度,因此标签可以具有可变长度:

#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);
}

它将变换原点设置在选项卡条的右上角,然后首先将整个条带向左平移 100%,最后执行旋转。

于 2015-12-17T17:29:47.407 回答