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

前端之家收集整理的这篇文章主要介绍了html – 类似于Chrome的样式标签栏?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我目前正在尽可能准确地重新创建Google Chrome的标签栏。但事实证明比我想象的要复杂得多。

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

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

有任何想法吗?

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

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

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

  1. body {
  2. background: #21C256; /* green windows theme */
  3. /* using transparency the tabbar should automatically adjust itself to whatever color is defined here */
  4. }
  5. .tab-bar {
  6. height: 23px; /* tab height */
  7. cursor: default;
  8. user-select: none; /* disable text selection */
  9. -webkit-touch-callout: none;
  10. -webkit-user-select: none;
  11. -khtml-user-select: none;
  12. -moz-user-select: none;
  13. -ms-user-select: none;
  14. pointer-events: none; /* disable image drag */
  15. margin: 0;
  16. padding: 0px 7px 0px 7px;
  17. }
  18. .tab {
  19. background: #FFFFFF; /* inactive tab background color */
  20. opacity: 0.726; /* inactive tab transparency */
  21. width: 213px; /* tab width */
  22. //max-width: 213px; /* messes up the trapezoid angles */
  23. margin-left: 0px; /* tab overlap */
  24. float: left;
  25. overflow: hidden;
  26. height: 100%;
  27. /*padding-bottom: 1px;*/
  28. border-radius: 3px; /* tab curves */
  29. transform: perspective(100px) rotateX(20deg); /* tab shape angle */
  30. Box-shadow: 0 0 2pt 0 rgba(0,0.9); /* tab outline */
  31. white-space: nowrap;
  32. padding-left: 8px; /* icon left side margin */
  33. display: block;
  34. vertical-align: middle;
  35. z-index: -2; /* inactive tabs are generally in the background */
  36. }
  37. .tab:hover {
  38. opacity: 0.8;
  39. }
  40. .tab-content {
  41. transform: perspective(100px) rotateX(-20deg); /* untransform tab content (this makes stuff blurry! :( ) */
  42. -o-transform: perspective(100px) rotateX(-20deg);
  43. -ms-transform: perspective(100px) rotateX(-20deg);
  44. -moz-transform: perspective(100px) rotateX(-20deg);
  45. -webkit-transform: perspective(100px) rotateX(-20deg);
  46. -khtml-transform: perspective(100px) rotateX(-20deg);
  47. }
  48. .tab-icon {
  49. display: inline-block;
  50. vertical-align: middle;
  51. width: 16px;
  52. height: 16px;
  53. }
  54. .tab-text {
  55. display: inline-block;
  56. vertical-align: middle;
  57. font-family: arial,sans-serif; /* tab text font */
  58. text-rendering: geometricPrecision; /* tab text improve rendering */
  59. font-size: 12px; /* tab text size */
  60. -webkit-mask-image: linear-gradient(to right,#000,200px,transparent); /* make text fade at the right edge (webkit only)*/
  61. }
  62. .tab-close {
  63. display: inline-block;
  64. vertical-align: middle;
  65. width: 16px;
  66. height: 16px;
  67. right: 5px;
  68. background: url(http://250kb.de/u/160430/p/YlimbFeb56qF.png);
  69. }
  70. .tab-close:hover {
  71. background: url(http://250kb.de/u/160430/p/rNqZRYHpNQBr.png);
  72. }
  73. .active-tab {
  74. z-index: -1; /* active tab is in front of other tabs,but still behind the content Box */
  75. background: linear-gradient(to bottom,#FFFFFF,#F8F9F9); /* active tab color */
  76. position: relative;
  77. opacity: 1;
  78. padding-bottom: 2px;
  79. }
  80. .active-tab:hover {
  81. opacity: 1;
  82. }
  83.  
  84. .new-tab {
  85. overflow: hidden;
  86. float: left;
  87. width: 25px; /* new-tab-button width */
  88. height: 14px; /* new-tab-button height */
  89. margin-top: 5px; /* to vertically center the new-tab-button */
  90. margin-left: 7px; /* margin between tabs and new-tab-button */
  91. Box-shadow: 0 0 1pt 0 rgba(0,0.9); /* new-tab-button outline */
  92. background: #FFFFFF; /* new-tab-button color */
  93. opacity: 0.626; /* new-tab-button transparency */
  94. border-radius: 2px; /* new-tab-button curves */
  95. transform: skew(20deg); /* new-tab-button shape angle */
  96. -o-transform: skew(20deg);
  97. -ms-transform: skew(20deg);
  98. -moz-transform: skew(20deg);
  99. -khtml-transform: skew(20deg);
  100. -webkit-transform: skew(20deg);
  101. }
  102. .new-tab:hover {
  103. opacity: 0.8;
  104. }
  105.  
  106. #content {
  107. z-index: 1; /* the content Box is always in the foreground */
  108. width: 100%;
  109. height: 50px;
  110. background: #F8F9F8;
  111. border-radius: 3px;
  112. }
  1. <ul class="tab-bar">
  2.  
  3. <li class="tab">
  4. <div class="tab-content">
  5. <img class="tab-icon" src="http://amazon.com/favicon.ico"/>
  6. <span class="tab-text">Amazon.com: Online Shopping for Electronics,Apparel,Computers,Books,DVDs & more</span>
  7. <span class="tab-close"></span>
  8. </div>
  9. </li>
  10. <li class="tab active-tab">
  11. <div class="tab-content">
  12. <img class="tab-icon" src="http://google.com/favicon.ico"/>
  13. <span class="tab-text">Google</span>
  14. <span class="tab-close"></span>
  15. </div>
  16. </li>
  17. <li class="new-tab"></li>
  18. </ul>
  19.  
  20. <div id="content">
  21.  
  22. </div>

解决方法

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

https://jsfiddle.net/2p74co0q/

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

猜你在找的HTML相关文章