有没有办法使用 CSS 创建类似 chrome 的选项卡?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5322895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to create a chrome-like tab using CSS?
提问by user220755
I have been looking for a Google Chrome-like tab written using CSS but cannot find one.
我一直在寻找使用 CSS 编写的类似 Google Chrome 的选项卡,但找不到。
I am trying to replicate the look in order to use it in a web application or a website.
我正在尝试复制外观,以便在 Web 应用程序或网站中使用它。
回答by Jacob Lowe
yeah its possible, with css3
是的,它可能,使用 css3
Ive posted a blog about how to its a lil depthy, and sadly enouth not going to work on ie unless you use images
我已经发布了一个关于如何深入的博客,遗憾的是,除非你使用图像,否则它不会在 ie 上工作
Edit:
编辑:
Removed old reference to redeyeoperations cause its a link farm now. This is a bit lighter version also it is up on a 3rd party site, so its less likely to be down.
删除了对 redeyeoperations 的旧引用,现在它是一个链接农场。这是一个更轻的版本,它也在第 3 方网站上运行,因此它不太可能关闭。
http://codepen.io/jacoblwe20/pen/DxAJF
http://codepen.io/jacoblwe20/pen/DxAJF
Here is the code
这是代码
HTML
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
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 ~ include jquery to get working or visit the codepen
用于选项卡切换的 JS ~ 包括 jquery 以开始工作或访问 codepen
var tabs = $('.tabs > li');
tabs.on("click", function(){
tabs.removeClass('active');
$(this).addClass('active');
});
回答by Shoib Mohammed A
I am just giving some css for getting chrome like tabs, rest its up to you to use as you want.
我只是提供一些 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>
demo here http://jsfiddle.net/GH7d6/
回答by srigi
I found this in CSS tricks, really deeply hidden:
我在 CSS 技巧中发现了这个,真的很深:
回答by splintor
This github projectseems to do it, but it doesn't look that good on my IE 11... :(
这个 github 项目似乎做到了,但它在我的 IE 11 上看起来不太好...... :(
回答by Abdennour TOUMI
What about this : http://codepen.io/justd/pen/dPeKEG/
这个怎么样:http: //codepen.io/justd/pen/dPeKEG/
Find 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;
}
}
}
回答by Jhourlad Estrella
Have you tried jQuery UI which can be found here:
您是否尝试过可以在此处找到的 jQuery UI:
回答by justd
If you need solution in Bootstrap and AngularJS I made one myself. They're styled with overriding the default Bootstrap styles.
如果你需要 Bootstrap 和 AngularJS 的解决方案,我自己做了一个。它们的样式覆盖了默认的 Bootstrap 样式。
You can check the tutorial here: https://scotch.io/tutorials/build-chrome-like-tabs-with-bootstrap-and-angularjs
您可以在此处查看教程:https: //scotch.io/tutorials/build-chrome-like-tabs-with-bootstrap-and-angularjs
And grab the code here: https://github.com/imjustd/chrome-tabs
并在此处获取代码:https: //github.com/imjustd/chrome-tabs
回答by Felipe Augusto Gonalves Basili
I created heretabs like google chrome stylish UI, you can find the light and dark themes in the attached pen.
我在这里创建了类似 google chrome 时尚 UI 的标签,您可以在附带的笔中找到明暗主题。
<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>