加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – 类似于Chrome的样式标签栏?

发布时间:2020-12-14 21:41:36 所属栏目:资源 来源:网络整理
导读:我目前正在尽可能准确地重新创建Google Chrome的标签栏。但事实证明比我想象的要复杂得多。 它已经看起来很相似,但我注意到几个问题: 当标签调整大小时,角度变得混乱 z-indexing不能按预期工作 悬停事件不起作用 哪里的标签重叠它看起来不好 文本不是垂直
我目前正在尽可能准确地重新创建Google Chrome的标签栏。但事实证明比我想象的要复杂得多。

它已经看起来很相似,但我注意到几个问题:

>当标签调整大小时,角度变得混乱
> z-indexing不能按预期工作
>悬停事件不起作用
>哪里的标签重叠它看起来不好
>文本不是垂直居中的(在Firefox中它实际上是工作的)
>选项卡底部缺少曲线
> x按钮不贴在右边

有任何想法吗?

我试图查看chromes源代码,看看是否可以找到原始的颜色/透明度/曲线值,但是I couldn’t find anything。

在我忘记之前,如果可能的话,我希望这可能与IE8或多或少兼容,即使这意味着标签不能是梯形形状等。

EDIT2:从零开始重写整个事情。 (对于新的标签按钮,本·莱斯 – 刘易斯的信用)
https://jsfiddle.net/p7vxzLjq/17/

body {
  background: #21C256; /* green windows theme */
  /* using transparency the tabbar should automatically adjust itself to whatever color is defined here */
}
.tab-bar {
  height: 23px; /* tab height */
  cursor: default;
  user-select: none; /* disable text selection */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -khtml-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  pointer-events: none; /* disable image drag */
  margin: 0;
  padding: 0px 7px 0px 7px;
}
.tab {
  background: #FFFFFF; /* inactive tab background color */
  opacity: 0.726; /* inactive tab transparency */
  width: 213px; /* tab width */
  //max-width: 213px; /* messes up the trapezoid angles */
  margin-left: 0px; /* tab overlap */
  float: left;
  overflow: hidden;
  height: 100%;
  /*padding-bottom: 1px;*/
  
  border-radius: 3px; /* tab curves */
  transform: perspective(100px) rotateX(20deg); /* tab shape angle */
  box-shadow: 0 0 2pt 0 rgba(0,0.9); /* tab outline */
  
  white-space: nowrap;
  padding-left: 8px; /* icon left side margin */
  display: block;
  vertical-align: middle;
  z-index: -2;  /* inactive tabs are generally in the background */
}
.tab:hover {
  opacity: 0.8;
}
.tab-content {
  transform: perspective(100px) rotateX(-20deg); /* untransform tab content (this makes stuff blurry! :( ) */
  -o-transform: perspective(100px) rotateX(-20deg);
  -ms-transform: perspective(100px) rotateX(-20deg);
  -moz-transform: perspective(100px) rotateX(-20deg);
  -webkit-transform: perspective(100px) rotateX(-20deg);
  -khtml-transform: perspective(100px) rotateX(-20deg);
}
.tab-icon {
  display: inline-block;
  vertical-align: middle;
  width: 16px;
  height: 16px;
}
.tab-text {
  display: inline-block;
  vertical-align: middle;
  font-family: arial,sans-serif; /* tab text font */
  text-rendering: geometricPrecision; /* tab text improve rendering */
  font-size: 12px; /* tab text size */
  -webkit-mask-image: linear-gradient(to right,#000,200px,transparent); /* make text fade at the right edge (webkit only)*/
}
.tab-close {
  display: inline-block;
  vertical-align: middle;
  width: 16px;
  height: 16px;
  right: 5px;
  background: url(http://250kb.de/u/160430/p/YlimbFeb56qF.png);
}
.tab-close:hover {
  background: url(http://250kb.de/u/160430/p/rNqZRYHpNQBr.png);
}
.active-tab {
  z-index: -1; /* active tab is in front of other tabs,but still behind the content box */
  background: linear-gradient(to bottom,#FFFFFF,#F8F9F9); /* active tab color */
  position: relative;
  opacity: 1;
  padding-bottom: 2px;
}
.active-tab:hover {
  opacity: 1;
}

.new-tab {
  overflow: hidden;
  float: left;
  width: 25px; /* new-tab-button width */
  height: 14px; /* new-tab-button height */
  margin-top: 5px; /* to vertically center the new-tab-button */
  margin-left: 7px; /* margin between tabs and new-tab-button */
  box-shadow: 0 0 1pt 0 rgba(0,0.9); /* new-tab-button outline */
  background: #FFFFFF; /* new-tab-button color */
  opacity: 0.626; /* new-tab-button transparency */
  border-radius: 2px; /* new-tab-button curves */
  transform: skew(20deg); /* new-tab-button shape angle */
  -o-transform: skew(20deg);
  -ms-transform: skew(20deg);
  -moz-transform: skew(20deg);
  -khtml-transform: skew(20deg);
  -webkit-transform: skew(20deg); 
}
.new-tab:hover {
  opacity: 0.8;
}

#content {
  z-index: 1; /* the content box is always in the foreground */
  width: 100%;
  height: 50px;
  background: #F8F9F8;
  border-radius: 3px;
}
<ul class="tab-bar">

  <li class="tab">
    <div class="tab-content">
      <img class="tab-icon" src="http://amazon.com/favicon.ico"/>
      <span class="tab-text">Amazon.com: Online Shopping for Electronics,Apparel,Computers,Books,DVDs & more</span>
      <span class="tab-close"></span>
    </div>
  </li>
  
  <li class="tab active-tab">
    <div class="tab-content">
      <img class="tab-icon" src="http://google.com/favicon.ico"/>
      <span class="tab-text">Google</span>
      <span class="tab-close"></span>
    </div>
  </li>
  
  <li class="new-tab"></li>
  
</ul>

<div id="content">

</div>

解决方法

这里是一个css形状的小提琴,就像你想要的新标签一样。
#newtab {
    width: 150px;
    height: 100px;
    -webkit-transform: skew(20deg);
       -moz-transform: skew(20deg);
         -o-transform: skew(20deg);
    background: #A8D5C1;
    margin-left: 20px;
    border-radius: 10px;
}

https://jsfiddle.net/2p74co0q/

对于透明度值,它很难从您的图像中看到,但我猜只是试错。显然,你的镀铬外观与我所使用的主题是如何不同的。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读