有没有办法使用CSS创建类似chrome的选项卡?

时间:2011-03-16 08:53:54

标签: css

我一直在寻找使用CSS编写的类似Google Chrome的标签,但找不到。

我正在尝试复制外观,以便在Web应用程序或网站中使用它。

8 个答案:

答案 0 :(得分:16)

是的,有可能,用css3

我发布了一篇关于如何使用lil deepy的博客,遗憾的是,除非你使用图像,否则不能继续工作

编辑:

删除旧的redyeoperations引用现在导致它的链接服务器场。 这是一个更轻的版本,它也在第三方网站上,所以它不太可能失败。

http://codepen.io/jacoblwe20/pen/DxAJF

这是代码

HTML

<div class=tab-container>
  <ul class="tabs clearfix" >
    <li>
      <a href=# >Users</a> 
    </li>
    <li class=active > 
      <a href=# >Pending Lots</a> 
    </li>
    <li> 
      <a href=# >Nearby Lots</a> 
    </li>
    <li>
      <a href=# >Recent Lots</a>
    </li>
  </ul>
</div>
<div class=outer-circle></div>

CSS

body{
  background : #efefef;
  font : .8em sans-serif;
  margin: 0;
}

.tab-container{
  background : #2BA6CB;
  margin: 0;
  padding: 0;
  max-height: 35px;
}

ul.tabs{
  margin: 0;
  list-style-type : none;
  line-height : 35px;
  max-height: 35px;
  overflow: hidden;
  display: inline-block;
  padding-right: 20px
}

ul.tabs > li.active{
  z-index: 2;
  background: #efefef;
}

ul.tabs > li.active:before{
  border-color : transparent #efefef transparent transparent;
}


ul.tabs > li.active:after{
  border-color : transparent transparent transparent #efefef;
}

ul.tabs > li{
  float : right;
  margin : 5px -10px 0;
  border-top-right-radius: 25px 170px;
  border-top-left-radius: 20px 90px;
  padding : 0 30px 0 25px;
  height: 170px;
  background: #ddd;
  position : relative;
  box-shadow: 0 10px 20px rgba(0,0,0,.5);
  max-width : 200px;
}

ul.tabs > li > a{
  display: inline-block;
  max-width:100%;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
  color: #222;
}

ul.tabs > li:before, ul.tabs > li:after{
  content : '';
  background : transparent;
  height: 20px;
  width: 20px;
  border-radius: 100%;
  border-width: 10px;
  top: 0px;
  border-style : solid;
  position : absolute;
}

ul.tabs > li:before{
  border-color : transparent #ddd transparent transparent;
  -webkit-transform : rotate(48deg);
  -moz-transform : rotate(48deg);
  -ms-transform : rotate(48deg);
  -o-transform : rotate(48deg);
  transform : rotate(48deg);
  left: -23px;
}

ul.tabs > li:after{
  border-color : transparent transparent transparent #ddd;
  -webkit-transform : rotate(-48deg);
  -moz-transform : rotate(-48deg);
  -ms-transform : rotate(-48deg);
  -o-transform : rotate(-48deg);
  transform : rotate(-48deg);
  right: -17px;
}

/* Clear Fix took for HTML 5 Boilerlate*/

.clearfix:before, .clearfix:after { content: ""; display: table; }
.clearfix:after { clear: both; }
.clearfix { zoom: 1; }

JS for tab switching~包括jquery来工作或访问codepen

var tabs = $('.tabs > li');

tabs.on("click", function(){
  tabs.removeClass('active');
  $(this).addClass('active');
});

答案 1 :(得分:5)

我在CSS技巧中找到了这个,真的很隐蔽:

http://css-tricks.com/examples/MovingHighlight/

答案 2 :(得分:5)

我只是给了一些css来获取像Chrome一样的标签,让你可以根据需要使用它。

<style type='text/css'>
  .chrome_tab {
    width: 150px;
    height: 0;
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-bottom: 20px solid grey;
    border-radius: 80px 80px 2px 2px;
    color: white;
    text-align: center;
  }
</style>


<div class='chrome_tab'>
    muhammad(peace be upon him)
</div>

这里的演示 http://jsfiddle.net/GH7d6/

答案 3 :(得分:2)

This github project似乎是这样做的,但它在IE 11上看起来并不好...... :(

答案 4 :(得分:1)

这是怎么回事: http://codepen.io/justd/pen/dPeKEG/

查找tuto here

@import "compass/css3";

@import "compass";

.tab-container {
  background: #8dc8fb;
  margin: 0;
  padding: 0;
  max-height: 40px;

  ul {
    &.nav-tabs {
      margin: 0;
      list-style-type: none;
      line-height: 40px;
      max-height: 40px;
      overflow: hidden;
      display: inline-block;
      @include display-flex;
      padding-right: 20px;
      border-bottom: 5px solid #f7f7f7;

      $color: #c3d5e6;

      > li {
        $raduis: 28px 145px;

        margin: 5px -14px 0;
        @include border-top-left-radius($raduis);
        @include border-top-right-radius($raduis);
        padding: 0 30px 0 25px;
        height: 170px;
        background: $color;
        position: relative;
        @include box-shadow(0 4px 6px rgba(0,0,0,.5));
        width: 200px;
        max-width: 200px;
        min-width: 20px;
        border:1px solid #aaa;

        &:first-child {
          margin-left: 0;
        }

        &:last-of-type {
          margin-right: 0;
        }

        > a {
          display: block;
          max-width:100%;
          text-decoration: none;
          color: #222;
          padding: 3px 7px;

          span {
            overflow: hidden;
            white-space: nowrap;
            display: block;
          }

          &:focus,
          &:hover {
            background-color: transparent;
            border-color: transparent;
          }

          .glyphicon-remove {
            color: #777;
            display: inline-block;
            padding:3px;
            font-size: 10px;
            position:absolute;
            z-index: 10;
            top:7px;
            right: -10px;
            @include border-radius(50%);

            &:hover {
              background: #d39ea3;
              color: white;
              @include box-shadow(inset 0 1px 1px rgba(0,0,0,.25));
              @include text-shadow(0 1px 1px rgba(0,0,0,.25));
            }
          }
        }

        &.active {
          z-index: 2;
          @include background-image(linear-gradient(white, #f7f7f7 30px));

          > a {
            background-color: transparent;
            border-color: transparent;
            border-bottom-color: transparent;

            &:focus,
            &:hover {
              background-color: transparent;
              border-color: transparent;
              border-bottom-color: transparent;
            }
          }
        }
      }

      .btn {
        float: left;
        height: 20px;
        width: 35px;
        min-width: 35px;
        max-width: 35px;
        margin: 10px 0 0 0;
        border-color: #71a0c9;
        outline: none;

        @include transform(skew(30deg));

        &.btn-default {
          background: $color;

          &:hover {
            background: #d2deeb;
          }

          &:active {
            background: #9cb5cc;
          }
        }
      }
    }
  }

  .tab-pane {
    padding: 60px 40px;
    text-align: center;

    &.active {
      border-top:1px solid #ddd;
    }
  }
}

答案 5 :(得分:0)

您是否尝试过jQuery UI,可以在这里找到:

http://jqueryui.com

答案 6 :(得分:0)

如果您需要Bootstrap和AngularJS中的解决方案,我自己制作了一个。它们的样式覆盖了默认的Bootstrap样式。

您可以在此处查看教程: https://scotch.io/tutorials/build-chrome-like-tabs-with-bootstrap-and-angularjs

在此处抓取代码:https://github.com/imjustd/chrome-tabs

答案 7 :(得分:-1)

我创建了here标签,例如google chrome时尚的用户界面,您可以在随附的笔中找到浅色和深色主题。

<div grid class="group-tabs">

    <!-- START GRID TAB 001 -->
    <input hide="hide" type="radio" tab id="rTab-1" name="tab" checked="checked">
    <label class='grid-label' for='rTab-1'><span>Tab 1</span></label>
    <div flex class="tab-content">
        <div dark grid class="group-tabs">

            <!-- START GRID TAB 0015 -->
            <input hide="hide" type="radio" tab id="rTab-15" name="tab2" checked="checked">
            <label class='grid-label' for='rTab-15'>
                <div icon icon-only>
                    <svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="adobe" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-adobe fa-w-16 fa-7x">
                        <path fill="currentColor" d="M315.5 64h170.9v384L315.5 64zm-119 0H25.6v384L196.5 64zM256 206.1L363.5 448h-73l-30.7-76.8h-78.7L256 206.1z" class=""></path>
                    </svg>
                </div>

            </label>
            <div flex class="tab-content">
                Icon on tab
            </div>
            <!-- END GRID TAB 0015 -->

            <!-- START GRID TAB 0016 -->
            <input hide="hide" type="radio" tab id="rTab-16" name="tab2">
            <label class='grid-label' for='rTab-16'><span>Tab 16</span></label>
            <div flex class="tab-content">
                What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Where does it come from? Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham. Where can I get some? There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
            </div>
            <!-- END GRID TAB 0016 -->
        </div>
    </div>
    <!-- END GRID TAB 001 -->

    <!-- START GRID TAB 002 -->
    <input hide="hide" type="radio" tab id="rTab-2" name="tab">
    <label class='grid-label' for='rTab-2'><span>Tab 2</span></label>
    <div flex class="tab-content">
        content 02
    </div>
    <!-- END GRID TAB 002 -->
    enter code here
</div>