【问题标题】:Style tab-bar like in Chrome?像 Chrome 中的样式标签栏?
【发布时间】:2016-04-28 14:32:21
【问题描述】:

我正在尝试使用 HTML/CSS 尽可能准确地重新创建 Google Chrome 的标签栏。但事实证明它比我想象的要复杂得多。

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

  • 调整选项卡大小时,角度会变得混乱
  • z 索引未按预期工作
  • 悬停事件不起作用
  • 标签重叠的地方看起来很糟糕
  • 文本不是垂直居中的(在 Firefox 中它确实有效)
  • 标签底部缺少曲线
  • x 按钮不靠右

有什么想法吗?

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

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

EDIT2:从头开始重写整个内容。 (感谢 Ben Rhys-Lewis 的新标签按钮)
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, 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, #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, 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>

【问题讨论】:

标签: html css google-chrome tabs


【解决方案1】:

好的,这里是一个 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/

对于透明度值,很难从您的图像中看到,但我想只是反复试验。显然,由于您使用的主题,您的 chrome 外观与我的外观不同。

【讨论】:

  • 感谢选项卡按钮。我已经走了好几个小时的试错路线,但我就是想不通。现在我想起来了,也许 chrome 不仅在应用透明度,而且还在改变亮度或类似的东西.. 至少这可以解释为什么我无法通过改变不透明度值来匹配 RGB。
  • 是的,可能。为什么需要这么精确?从图像上看,它基本上就在那里。
  • 好的,颜色不必100%与原版一致。但是除了颜色之外还有其他的东西。由于标签是透明的,它们重叠的地方看起来很奇怪。并且在标签接触标签栏的地方缺少一条轻微的曲线。当我在选项卡上显示文本时,它会发生奇怪的变化,看起来根本不像原来的。
  • 我敢打赌标签不透明。正如 Ben 所说,由于您使用的是第三方主题,因此很难知道,但我敢打赌,这只是标签栏背景颜色的褪色版本。
【解决方案2】:

必须改变很多东西才能正常工作。这是Fiddle。关于更改的一些说明:

  • 由于选项卡类上的pointer-events 属性,悬停不起作用。你可以把它放在tab-close 类下,或者你可以使用 jQuery 解决方案让它在旧浏览器中工作。
  • 我看不出有任何理由使用否定的z-index。我没有使用,它似乎工作。
  • 要使vertical-align 正常工作,您应该有一个常量line-height。将line-height 属性添加到选项卡类并让所有子类继承它,以便它们正确对齐到中间。还必须用额外的 div 包装图像才能正确对齐。
  • 关于重叠,如果您想要 Chrome 标签页中的结果,则不应使用不透明度。无论你做什么,如果你有不透明度,结果就会是这样。您可以改用常量颜色。
  • 为底部曲线和阴影添加了新元素。不确定它是否是必须的,但它看起来更像 Chrome 标签页。

让它在 IE8 中工作

我在 IE8 上对其进行了测试,但看起来并不令人愉快。不知道从哪里开始。以下是一些想法:

  • vertical-align 将无法可靠地工作。您可以使用vertical-align 放弃所有内容并使用常量absolute 定位。这意味着您无法根据需要更改标签大小,您必须选择一个常量。
  • 您必须编写所有transformopacity 属性的filter 等效项。你的 CSS 看起来就像地狱中最黑暗的地方。
  • border-radius 将不起作用。有一些我不建议的肮脏的解决方法。 box-shadow 也一样。

body {
    background: #21C256;
    /* green windows theme */
    /* using transparency the tabbar should automatically adjust itself to whatever color is defined here */
}

.tab-bar {
    height: 26px;
    /* tab height */
    line-height: 26px;
    /* this is critical for vertical alligning */
    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;
    margin: 0;
    padding: 0px 7px 0px 7px;
    z-index: 0;
    white-space: nowrap;
    display: block;
    overflow: hidden;
    width: 100%;
    margin: 0;
    font-size: 0;
}

.tab-bottom-curve-left {
    background: inherit;
    border: inherit;
    opacity: inherit;
    border-left: none;
    border-bottom: none;
    width: 10px;
    height: 4px;
    position: absolute;
    left: -5px;
    bottom: -2px;
    z-index: 5;
    transform: rotate(-31deg);
}

.tab-bottom-curve-right {
    background: inherit;
    border: inherit;
    opacity: inherit;
    border-left: none;
    border-bottom: none;
    width: 10px;
    height: 4px;
    position: absolute;
    right: -5px;
    bottom: -2px;
    transform: rotate(31deg);
    /* box-shadow: inherit; */
    z-index: 0;
}

.tab-icon {
    pointer-events: none;
    /* disable image drag */
}

.tab-text {
    width: 80%;
    height: 100%;
    padding-left: 4px;
}

.tab {
    background: #FFFFFF;
    /* inactive tab background color */
    opacity: 0.726;
    /* inactive tab transparency */
    width: 213px;
    /* tab width */
    margin-left: 0px;
    /* tab overlap */
    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, 0, 0.9);
    /* tab outline */
    white-space: nowrap;
    padding-left: 8px;
    /* icon left side margin */
    vertical-align: middle;
    z-index: 1;
    /* inactive tabs are generally in the background */
    line-height: inherit;
    /* margin-left: -1px; */
    /* margin-right: -1px; */
    /* margin-top: -6px; */
    height: 100%;
    vertical-align: top;
    font-size: 0;
    margin-top: 1px;
    overflow: visible;
    position: relative;
    display: inline-block;
    float: left;
    display: block;
}

.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);
    line-height: inherit;
    z-index: 5;
    height: 100%;
    font-size: 0;
    overflow: hidden;
    /* position: absolute; */
}

.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, #000, 165px, transparent);
    /* make text fade at the right edge (webkit only)*/
    overflow: hidden;
}

.tab-close {
    display: inline-block;
    height: 100%;
    width: 16px;
    line-height: inherit;
    right: 5px;
    position: absolute;
    z-index: 100000;
    vertical-align: middle;
}

.tab-close-img {
    display: inline-block;
    position: relative;
    vertical-align: middle;
    width: 16px;
    height: 16px;
    background: url(http://250kb.de/u/160430/p/YlimbFeb56qF.png);
}

.tab-close-img:hover {
    background: url(http://250kb.de/u/160430/p/rNqZRYHpNQBr.png);
}

.active-tab {
    z-index: 2;
    /* 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;
    width: 25px;
    /* new-tab-button width */
    height: 14px;
    /* new-tab-button height */
    /* margin-top: 7px; */
    /* to vertically center the new-tab-button */
    margin-left: 6px;
    /* margin between tabs and new-tab-button */
    vertical-align: middle;
    box-shadow: 0 0 1pt 0 rgba(0, 0, 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);
    display: inline-block;
}

.new-tab:hover {
    opacity: 0.8;
}

#content {
    position: absolute;
    z-index: 3;
    /* the content box is always in the foreground */
    width: 100%;
    height: 50px;
    background: #F8F9F8;
    border-radius: 3px;
}

.tab-bottom-shadow {
    /* width: 100%; */
    position: absolute;
    background: black;
    height: 1px;
    bottom: -1px;
    left: 0px;
    right: 0;
    box-shadow: 0 0 4px black;
    z-index: 5;
}

.active-tab .tab-bottom-shadow {
    display: none;
}
<div class="tab-bar">

        <div class="tab">
            <div class="tab-content">
                <span class="tab-icon-wrap"><img class="tab-icon" src="http://amazon.com/favicon.ico" /></span>
                <span class="tab-text">Amazon.com: Online Shopping for Electronics, Apparel, Computers, Books, DVDs & more</span>
                <span class="tab-close"><span class="tab-close-img"></span></span>
            </div>
            <div class="tab-bottom-curve-left"></div>
            <div class="tab-bottom-curve-right"></div>
            <div class="tab-bottom-shadow"></div>
        </div>

        <div class="tab">
            <div class="tab-content">
                <span class="tab-icon-wrap"><img class="tab-icon" src="http://youtube.com/favicon.ico" /></span>
                <span class="tab-text">YouTube</span>
                <span class="tab-close"><span class="tab-close-img"></span></span>
            </div>
            <div class="tab-bottom-curve-left"></div>
            <div class="tab-bottom-curve-right"></div>
            <div class="tab-bottom-shadow"></div>
        </div>

        <div class="tab active-tab">
            <div class="tab-content">
                <span class="tab-icon-wrap"><img class="tab-icon" src="http://google.com/favicon.ico" /></span>
                <span class="tab-text">Google</span>
                <span class="tab-close"><span class="tab-close-img"></span></span>
            </div>
            <div class="tab-bottom-curve-left"></div>
            <div class="tab-bottom-curve-right"></div>
            <div class="tab-bottom-shadow"></div>
        </div>

        <div class="new-tab"></div>

    </div>

    <div id="content">
    </div>

【讨论】:

  • 不错!关于不透明度:我真的不需要不透明度,我只需要标签自动调整到不同的颜色主题,不透明度是我唯一能想到的。底部的“曲线”在我看来更像是一个奇怪的尖峰或其他东西。对于 IE8,如果选项卡缺少形状和圆角等,只要它可以正常工作并且看起来“没问题”就可以了。无论如何,我仍然很担心像 Chrome 一样调整标签大小,如果标签没有图标怎么办? 250kb.de/u/160503/p/CsVgtTwnkKwy.png
  • 纯 css 无法自动调整大小。你应该涉及一些(很多)javascript。您还可以使用 javascript 来调整标签以适应不同的颜色。没有图标的标签看起来还不错。关于 IE8 和其他东西,我给了你一些关于 css 工作原理的提示。休息是让你即兴发挥。您可以为 IE8 制作一个完全不同的样式表,或者您甚至可以使所有形状和圆角看起来与在较新的浏览器中相同。这取决于您的决心以及您要投入多少时间。
  • 虽然我说过自动调整大小是不可能的,但在jsfiddle.net/sirkurt53/w91r50wp/7 中的表格布局中以某种方式是可能的。根据我的经验,表格布局在大多数浏览器中的工作方式都不同,因此我建议使用 javascript 解决方案。
  • 不透明度问题可以通过添加box-shadow: inset 0 0 0 100px RGBa(255, 255, 255, 0.726); 并将background-color 设置为.tab 类中的body 来解决。同样的技巧当然可以应用于.nav:hover。演示:jsfiddle.net/michaelvandeweerd/krhLuq7w/1.
【解决方案3】:

你必须使用纯 CSS 吗?或者你可以使用图像映射。这样,您可以轻松创建链接、悬停事件,达到相同的效果。

http://www.image-maps.com/ 是用于此类项目的绝佳工具。您可以使用多边形工具来选择按钮。

如果这不是您想要的,请不要担心。

【讨论】:

  • 嗯,我更喜欢纯 CSS。但仔细想想,这在纯 CSS 中甚至是不可能的。我的意思是,如果允许标签自行调整大小,那么转换真的会搞砸,而且由于转换,文本变得很模糊,因为我想与 IE8 兼容,所以图像看起来可能是一个非常好的主意在任何浏览器中都一样。
  • 是的。我也更喜欢纯 css,但在某些情况下你只需要使用你所拥有的!
  • 此外,通过使用图像映射,您可以消除所有浏览器兼容性问题
【解决方案4】:

请使用以下代码。我想这就是你要找的。 Demo

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;
  display: flex;
  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%;
  display: flex;
  /*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, 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 {
  display: flex;
  justify-content: space-between;
    padding: 4px 9px 0px 0px;
  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;
  text-align: left;
    width: 76%;
  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, #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, 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;
}

【讨论】:

  • 在 Firefox 中看起来不错,但在 IE10 及以下版本中不起作用。此外,标签的基本形状(角度)不应在其宽度发生变化时发生变化。
  • 哦....!!对于 Internet Explorer,您需要更改逻辑..尝试使用显示表。一会儿我会更新代码。
【解决方案5】:

如果您希望标签正确重叠,则必须删除透明度。我的解决方案还包括其他各种改进:

body {
  background: #21C256; /* green windows theme */
  /* using transparency the tabbar should automatically adjust itself to whatever color is defined here */
}
.tab-bar {
  height: 25px; /* 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;
}
.tab {
  background: #BAF1CB; /* inactive tab background color */
  opacity: 1; /* inactive tab transparency */
  width: 213px; /* tab width */
  margin-left: 0px; /* tab overlap */
  float: left;
  overflow: hidden;
  height: 100%;
  padding: 1px 0;
  
  border-radius: 3px; /* tab curves */
  transform: perspective(100px) rotateX(20deg); /* tab shape angle */
  box-shadow: 2px -2px 2px -2px black, -2px -1px 2px -2px black; /* 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 {
  background-color: #D0F5DB;
}
.tab-content {
  padding: 2px 0;
  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, #000, 200px, transparent); /* make text fade at the right edge (webkit only)*/
  max-width: 170px;
  overflow: hidden;
}
.tab-close {
  float: right;
  display: inline-block;
  vertical-align: middle;
  width: 16px;
  height: 16px;
  margin: 3px 5px 0 0;
  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: 1000000; /* 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, 0, 0.9); /* new-tab-button outline */
  background: #FFFFFF; /* new-tab-button color */
  opacity: 0.65; /* 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 {
  position: relative;
  z-index: 2; /* the content box is always in the foreground */
  width: 100%;
  height: 50px;
  background: #F8F9F8;
  border-radius: 3px;
  border: 1px solid #aaaaaa;
  border-width: 1px 0 0 0;
}
<ul class="tab-bar">

  <li class="tab">
    <div class="tab-content">
      <!-- Move the close-Button to the beginning -->
      <span class="tab-close"></span>
      <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>
    </div>
  </li>
  
  <li class="tab active-tab">
    <div class="tab-content">
      <span class="tab-close"></span>
      <img class="tab-icon" src="http://google.com/favicon.ico"/>
      <span class="tab-text">Google</span>
    </div>
  </li>
  
  <li class="new-tab"></li>
  
</ul>

<div id="content">

</div>

【讨论】:

  • 在 IE11、IE10 和 Firefox 中尝试过。悬停事件根本不起作用。 ://
  • 作者也没有在小提琴中工作。我没有改变它们。
猜你喜欢
  • 2011-03-13
  • 2022-06-28
  • 2018-08-09
  • 1970-01-01
  • 2014-09-21
  • 1970-01-01
  • 2010-10-25
  • 1970-01-01
  • 2019-09-05
相关资源
最近更新 更多