我需要这样做。纯css有可能吗?
答案 0 :(得分:12)
使用border-radius
,:before
和transform: skew(...);
body {
background-color: #000;
margin: 0;
padding: 0;
font-family: sans-serif;
font-size: 16px;
}
.tab {
height: 50px;
width: 150px;
border-radius: 15px 15px 0px 0px;
background-color: #FFF;
position: relative;
top: 10px;
left: 1px;
display: inline-block;
z-index: 2;
}
.tab:before {
height: 50px;
width: 70px;
border-radius: 10px 10px 0px 0px;
background-color: white;
content: "";
position: absolute;
left: 104px;
top: 0px;
-webkit-transform: skewX(40deg);
transform: skewX(40deg);
z-index: -1;
}
.tab:nth-of-type(2) {
background-color: #555;
top: 10px;
left: 30px;
z-index: 1;
color: #EEE;
}
.tab:nth-of-type(2):before {
background-color: #555;
}
.tab:nth-of-type(2):hover,
.tab:nth-of-type(2):hover:before {
background-color: #159;
transition: 0.3s ease-out;
}
span {
display: inline-block;
width: 160px;
text-align: center;
height: 50px;
line-height: 50px;
z-index: 3;
}
#page {
background-color: white;
height: calc(100vh - 120px);
width: calc(100vw - 61px);
position: relative;
top: 10px;
left: 1px;
padding: 30px;
}
<nav id="tabs">
<div class="tab">
<span>Tab 1</span>
</div>
<div class="tab">
<span>Tab 2</span>
</div>
</nav>
<div id="page">
Lorem Ipsum dolor sit amet ...
</div>
答案 1 :(得分:6)
使用CSS3,使用border-radius
制作弯曲的标签边角,然后create a triangle使用较低的z-index
。
HTML:
<div class="tab">
<div class="arrow"></div>
</div>
CSS:
body
{
background-color: #666;
}
.tab
{
height: 50px;
width: 150px;
border-radius: 10px 10px 0px 0px;
background-color: #FFF;
position: relative;
}
.arrow
{
border-color: transparent transparent #FFF #FFF;
border-style: solid;
border-width: 23px 23px 23px 23px;
height:0;
width:0;
position:absolute;
bottom:0px;
right:-43px;
}
结果:http://jsfiddle.net/P3P3Z/2/
它并不完美,它可能在不同的浏览器上呈现不同,但应该让你开始。 :)有些东西必须稍微调整一下,看起来不错。
答案 2 :(得分:2)
这个问题引起了我的兴趣,所以这是一个有效的例子。
<html>
<style type="text/css">
body {
background: #000000;
}
#header {
height: 29px;
overflow: hidden;
}
#content {
background: #ffffff;
min-height: 200px;
padding: 10px;
border-top-right-radius: 10px;
border-top-right-radius: 10px;
}
#on {
background: #ffffff;
display: inline-block;
padding: 5px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
vertical-align: top;
}
#off {
background: #888888;
display: inline-block;
padding: 5px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
vertical-align: top;
margin-left: -40px;
}
#seperatoron {
border: none;
border-left: 25px solid white;
border-bottom: 0px;
height: 0px;
width: 0px;
display: inline-block;
position: relative;
margin-top: 10px;
border-right: 25px solid transparent;
border-top: 25px solid transparent;
margin-top: 4px;
margin-left: -2px;
}
#seperatoroff {
border: none;
border-left: 25px solid #888888;
border-bottom: 0px;
height: 0px;
width: 0px;
display: inline-block;
position: relative;
margin-top: 10px;
border-right: 25px solid transparent;
border-top: 25px solid transparent;
margin-top: 4px;
margin-left: -2px;
}
</style>
<body>
<div id="header">
<div id="on">Tab 1</div><div id="seperatoron"></div>
<div id="off">Tab 2</div><div id="seperatoroff"></div>
</div>
<div id="content">
Document content section.
</div>
</body>
</html>
答案 3 :(得分:1)
左上角的圆角边框可以使用border-radius属性(不是旧的IE版本)。但是,每个选项卡的右侧应该使用图像,svg或带有css3转换的旋转div来完成,但这肯定会让你头疼。
如果我是你,那么我会选择一个边界半径来进行topleft,并将背景图像对齐到右边:
border-top-left-radius: 10px;
background: white url(tab.gif) right top no-repeat;
我认为你还应该给第二个标签留下一个负边距。
答案 4 :(得分:0)
以下是带有css
的窗口类型标签按钮.tablist{
padding:0;
margin:0;
list-style:none;
display:flex;
justify-content:center;
}
.tablist>li{
}
.tablist >li>a{
position: relative;
display: block;
color: red;
text-decoration: none;
line-height: 1.4;
border-top: 1px solid red;
border-radius: 6px 6px 0 0;
padding: 3px 10px;
margin: 0 5px;
}
.tablist >li>a:before{
position: absolute;
content: "";
width: 9px;
height: 29px;
background: white;
transform: rotate(21deg);
border-left: 1px solid red;
left: -5px;
top: 2px;
z-index: -1;
border-radius: 2px 0 0 0px;
}
.tablist >li>a:after{
position: absolute;
content: "";
width: 9px;
height: 29px;
background: white;
transform: rotate(-21deg);
border-right: 1px solid red;
right: -5px;
top: 2px;
z-index: -1;
border-radius: 2px 0 0 0px;
}
html就像这样
<ul class="tablist">
<li><a href="jasscript:void(0)">Home</a></li>
<li><a href="jasscript:void(0)">About</a></li>
<li><a href="jasscript:void(0)">Contact us</a></li>
<li><a href="jasscript:void(0)">Blog</a></li>
<li><a href="jasscript:void(0)">Home</a></li>
</ul>