我需要这样做。纯CSS可以吗?
问问题
15124 次
5 回答
19
使用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>
于 2015-01-16T13:24:26.280 回答
7
使用 CSS3,用于border-radius
制作弯曲的标签角,然后创建一个带有下角的三角形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/
它并不完美,它可能在不同的浏览器上呈现不同,但应该让你开始。:) 有些东西必须稍微调整一下,这样看起来不错。
于 2012-01-17T13:51:12.033 回答
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>
于 2012-01-17T14:26:25.823 回答
1
左上角的圆形边框可以通过border-radius 属性实现(在旧的IE 版本中没有)。但是,每个选项卡的右侧应该使用图像、svg 或带有 css3 转换的旋转 div 来完成,但这肯定会让您头疼。
如果我是你,我会选择左上角的边框半径和右对齐的背景图像:
border-top-left-radius: 10px;
background: white url(tab.gif) right top no-repeat;
我认为你也应该给第二个标签一个负边距。
于 2012-01-17T13:51:15.477 回答
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>
于 2016-05-28T19:56:36.957 回答