如何使用css3实现的tab选项卡
这篇文章主要介绍“如何使用css3实现的tab选项卡”,在日常操作中,相信很多人在如何使用css3实现的tab选项卡问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何使用css3实现的tab选项卡”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
今天给大家带来一款纯css3实现的tab选项卡。单击左侧的选项的时候,右侧内容以动画的形式展示。效果图如下:
实现的代码。
html代码:
代码如下:
<div class="night-tabs night-tabs-color-default night-tabs-animation-slide-right night-tabs-position-vleft">
<!--Tab 1-->
<input type="radio" name="night-tabs" checked="" id="tab1" class="content1">
<!--Checked= Tab shown-->
<label for="tab1">
<!--Modify icon and name-->
<span><span><em class="fa fa-home"></em>Night Tabs</span></span>
</label>
<!--Tab 2-->
<input type="radio" name="night-tabs" id="tab2" class="content2">
<label for="tab2">
<!--Modify icon and name-->
<span><span><em class="fa fa-font"></em>Typography</span></span>
</label>
<!--Tab 3-->
<input type="radio" name="night-tabs" id="tab3" class="content3">
<label for="tab3">
<!--Modify icon and name-->
<span><span><em class="fa fa-list"></em>Grid Systen</span></span>
</label>
<!--Tab 4-->
<input type="radio" name="night-tabs" id="tab4" class="content4">
<label for="tab4">
<!--Modify icon and name-->
<span><span><em class="fa fa-legal"></em>License</span></span>
</label>
<!--Content-->
<ul class="night-tabs-content">
<!--Tab 1-->
<li class="content1">
<div class="content-1-content">
<!--Content goes here-->
<h2 class="h2">
Night Tabs</h2>
<p>
<span class="dropcap">N</span>ight Tabs (formerly TrueTabs) is an extensive CSS3
Tabbed Content snippet. It started out small as a typical CSS Tabs snippet, but
I have expanded it greatly. It offers many features, and can be easily modified
to fit your needs. Some of the features include: Cross browser support, preset animations,
colors, and layouts, a responsive grid system, and a typography set, among other
things.</p>
</div>
</li>
<!--Tab 2-->
<li class="content2">
<div class="content-2-content">
<!--Content goes here-->
<h2 class="h2">
Custom Fonts</h2>
<h3 class="h3">
Open Sans Light</h3>
<h4 class="h4">
<em class="fa fa-check"></em>FontAwesome</h4>
<p>
<h3 class="h3">
Paragraphs and Quotes</h3>
<blockquote class="blockquote">
Maecenas tincidunt nunc est, nec pharetra odio porta ac. Morbi cursus lacinia neque,
tristique tincidunt ipsum tincidunt a.
</blockquote>
<div class="well">
<p>
Maecenas tincidunt nunc est, nec pharetra odio porta ac. Morbi cursus lacinia neque,
tristique tincidunt ipsum tincidunt a.</p>
</div>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec malesuada rutrum
felis, quis imperdiet nisl finibus id. Etiam commodo vitae purus a lobortis. Donec
lacinia dapibus metus nec feugiat. Integer blandit tellus vel dapibus efficitur.
Nulla placerat sollicitudin laoreet. Maecenas fermentum eros diam, at blandit lectus
volutpat ac.Proin ornare mauris dui, semper condimentum urna blandit non. Vestibulum
ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Ut
scelerisque justo sit amet sem commodo, ac porta arcu auctor.</p>
<h4 class="h4">
Unordered Lists</h4>
<ul class="night-tabs-unordered-list">
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<ul class="night-tabs-unordered-list">
<li>Nulla vitae lacus sed dui fringilla elementum eu id eros.</li>
<li>Vivamus euismod mauris sit amet iaculis porttitor.</li>
<li>Donec condimentum massa non elit lobortis, a ultrices ante vulputate.</li>
</ul>
</li>
<li>Nulla vitae lacus sed dui fringilla elementum eu id eros.</li>
<li>Vivamus euismod mauris sit amet iaculis porttitor.</li>
<li>Donec condimentum massa non elit lobortis, a ultrices ante vulputate.</li>
</ul>
<h4 class="h4">
Ordered Lists</h4>
<ol class="night-tabs-ordered-list">
<li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<ol class="night-tabs-ordered-list">
<li>Nulla vitae lacus sed dui fringilla elementum eu id eros.</li>
<li>Vivamus euismod mauris sit amet iaculis porttitor.</li>
<li>Donec condimentum massa non elit lobortis, a ultrices ante vulputate.</li>
</ol>
</li>
<li>Nulla vitae lacus sed dui fringilla elementum eu id eros.</li>
<li>Vivamus euismod mauris sit amet iaculis porttitor.</li>
<li>Donec condimentum massa non elit lobortis, a ultrices ante vulputate.</li>
</ol>
<div class="text-right">
<em>Typography Set</em>
</div>
</div>
</li>
<!--Tab 3-->
<li class="content3">
<div class="content-3-content">
<!--Content goes here-->
<div class="grid-row">
<div class="grid-column grid-column-6">
<h3 class="h3">
HTML5</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ante nisl, condimentum
nec dolor viverra, dignissim convallis est. In commodo rhoncus augue, a euismod
felis placerat ut. Ut ullamcorper libero tortor, ut semper lectus congue ut. Morbi
pulvinar, nisi at pharetra scelerisque, nibh magna ornare augue, vel aliquet ipsum
ante eu sem. Maecenas id est risus. Nulla facilisis dui molestie euismod mollis.
Duis vehicula elementum justo in porta. Maecenas erat lectus, finibus vel lectus
non, consequat ultricies dolor. Nunc ultricies quam in purus facilisis, porttitor
blandit odio volutpat. Sed sed posuere lectus, sit amet rutrum est. Duis porttitor
purus blandit, lacinia nibh quis, ultricies augue.</p>
</div>
<div class="grid-column grid-column-6">
<h3 class="h3">
CSS3</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ante nisl, condimentum
nec dolor viverra, dignissim convallis est. In commodo rhoncus augue, a euismod
felis placerat ut. Ut ullamcorper libero tortor, ut semper lectus congue ut. Morbi
pulvinar, nisi at pharetra scelerisque, nibh magna ornare augue, vel aliquet ipsum
ante eu sem. Maecenas id est risus. Nulla facilisis dui molestie euismod mollis.
Duis vehicula elementum justo in porta. Maecenas erat lectus, finibus vel lectus
non, consequat ultricies dolor. Nunc ultricies quam in purus facilisis, porttitor
blandit odio volutpat. Sed sed posuere lectus, sit amet rutrum est. Duis porttitor
purus blandit, lacinia nibh quis, ultricies augue.</p>
</div>
</div>
<div class="grid-row">
<div class="grid-column grid-column-12">
<h3 class="h3">
NO JavaScript</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ante nisl, condimentum
nec dolor viverra, dignissim convallis est. In commodo rhoncus augue, a euismod
felis placerat ut. Ut ullamcorper libero tortor, ut semper lectus congue ut. Morbi
pulvinar, nisi at pharetra scelerisque, nibh magna ornare augue, vel aliquet ipsum
ante eu sem. Maecenas id est risus. Nulla facilisis dui molestie euismod mollis.
Duis vehicula elementum justo in porta. Maecenas erat lectus, finibus vel lectus
non, consequat ultricies dolor. Nunc ultricies quam in purus facilisis, porttitor
blandit odio volutpat. Sed sed posuere lectus, sit amet rutrum est. Duis porttitor
purus blandit, lacinia nibh quis, ultricies augue.</p>
</div>
<div class="text-right">
<em>Night Tabs - CSS3 Tabbed Content</em>
</div>
</div>
</div>
</li>
<!--Tab 4-->
<li class="content4">
<div class="content-4-content">
<!--Content goes here-->
<h2 class="h2">
Night Tabs - v0.2.0</h2>
<p>
Coded by Jason Shi under the MIT License.</p>
</div>
</li>
</ul>
</div>
css3代码:
代码如下:
.night-tabs a,
.night-tabs div,
.night-tabs em,
.night-tabs img,
.night-tabs ul,
.night-tabs label,
.night-tabs li,
.night-tabs ol,
.night-tabs p,
.night-tabs span,
.night-tabs ul {
border: 0;
margin: 0;
padding: 0;
position: relative;
box-sizing: border-box
}
.night-tabs {
margin: 0 auto;
width: 70%;
font: 300 0px/1.5
"Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #ecf0f1
}
.night-tabs input {display: none}
.night-tabs input:checked+label {cursor: default}
.night-tabs label {
display: inline-block;
z-index: 1;
border-bottom: 2px solid #353535;
border-right: 1px solid #444;
border-left: 1px solid #222;
cursor: pointer;
font-size: 18px;
line-height: 40px;
text-align: left;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none
}
.night-tabs label span {
display: block;
padding: .2em;
background: #404040
}
.night-tabs label span span {
border: 2px solid transparent;
padding: 0 1em;
-webkit-transition: background .4s;
transition: background .4s
}
.night-tabs .night-tabs-content {
display: block;
font-size: 18px
}
.night-tabs .night-tabs-content > li {
left: 0;
opacity: 0;
overflow: auto;
padding: 1em 1.5em;
position: absolute;
top: 0;
visibility: hidden;
width: 100%;
background: #404040;
-webkit-transform-origin: 0 0;
-ms-transform-origin: 0 0;
transform-origin: 0 0;
-webkit-transition: all .8s .1s;
transition: all .8s .1s
}
@charset "UTF-8";
.night-tabs>.content1:checked~ul>.content1,
.night-tabs>.content2:checked~ul>.content2,
.night-tabs>.content3:checked~ul>.content3,
.night-tabs>.content4:checked~ul>.content4 {
opacity: 1;
visibility: visible;
-webkit-transform: none;
-ms-transform: none;
transform: none
}
.night-tabs-animation-slide-up .night-tabs-content > li {
-webkit-transform: translateY(30px);
-ms-transform: translateY(30px);
transform: translateY(30px)
}
.night-tabs-slide-down .night-tabs-content > li {
-webkit-transform: translateY(-30px);
-ms-transform: translateY(-30px);
transform: translateY(-30px)
}
.night-tabs-animation-slide-left .night-tabs-content > li {
-webkit-transform: translateX(-30px);
-ms-transform: translateX(-30px);
transform: translateX(-30px)
}
.night-tabs-animation-slide-right .night-tabs-content > li {
-webkit-transform: translateX(30px);
-ms-transform: translateX(30px);
transform: translateX(30px)
}
.night-tabs-slide-up-left .night-tabs-content > li {
-webkit-transform: translate(-30px, -30px);
-ms-transform: translate(-30px, -30px);
transform: translate(-30px, -30px)
}
.night-tabs-animation-slide-up-right .night-tabs-content > li {
-webkit-transform: translate(30px, -30px);
-ms-transform: translate(30px, -30px);
transform: translate(30px, -30px)
}
.night-tabs-animation-slide-down-left .night-tabs-content > li {
-webkit-transform: translate(-30px, 30px);
-ms-transform: translate(-30px, 30px);
transform: translate(-30px, 30px)
}
.night-tabs-animation-slide-down-right .night-tabs-content > li {
-webkit-transform: translate(30px, 30px);
-ms-transform: translate(30px, 30px);
transform: translate(30px, 30px)
}
.night-tabs-rotate > ul > li {
-o-transform: rotate(10deg);
-ms-transform: rotate(10deg);
-moz-transform: rotate(10deg);
-webkit-transform: rotate(10deg)
}
.night-tabs-animation-rotate.night-tabs.night-tabs-position-vleft > ul > li,
.night-tabs-animation-rotate.night-tabs.night-tabs-position-vright > ul > li {
-o-transform: rotate(-10deg);
-ms-transform: rotate(-10deg);
-moz-transform: rotate(-10deg);
-webkit-transform: rotate(-10deg)
}
.night-tabs-animation-scale > ul > li {
-webkit-transform: scale(0.6, 0.6);
-ms-transform: scale(0.6, 0.6);
transform: scale(0.6, 0.6)
}
.night-tabs-animation-flip .night-tabs-content {
-webkit-perspective: 2000px;
perspective: 2000px;
-webkit-perspective-origin: 50% 50%;
perspective-origin: 50% 50%
}
.night-tabs-animation-flip .night-tabs-content > li {
-webkit-transform: rotateX(-90deg);
transform: rotateX(-90deg)
}
.night-tabs-animation-flip.night-tabs-position-vleft > .night-tabs-content > li {
-webkit-transform: rotateY(90deg);
transform: rotateY(90deg)
}
.night-tabs-animation-flip.night-tabs-position-vright > .night-tabs-content > li {
-webkit-transform: rotateY(-90deg);
transform: rotateY(-90deg)
}
.night-tabs-position-left label,
.night-tabs-position-center label,
.night-tabs-position-right label {width: auto}
.night-tabs-position-left {text-align: left}
.night-tabs-position-center {text-align: center}
.night-tabs-position-right {text-align: right}
.night-tabs-position-justify > input:first-child + label {padding-left: 0}
.night-tabs-position-justify2 > label {width: 50%}
.night-tabs-position-justify3 > label {width: 33.33%}
.night-tabs-position-justify4 > label {width: 25%}
.night-tabs-position-vleft .night-tabs-content > li,
.night-tabs-position-vright .night-tabs-content > li {border-top: 0}
.night-tabs-position-vleft > label,
.night-tabs-position-vright > label {
clear: left;
display: block;
float: left;
margin-right: 0;
width: 25%
}
.night-tabs-position-vleft label {border-right: 2px solid #333}
.night-tabs-position-vleft > .night-tabs-content {margin-left: 25%}
.night-tabs-position-vright > label {
clear: right;
float: right
}
.night-tabs-position-vright ul li { border-right: 1px solid #333}
.night-tabs-position-vright > .night-tabs-content {margin-right: 25%}
.night-tabs-position-vright .night-tabs-content > li {
-webkit-transform-origin: 100% 0%;
-ms-transform-origin: 100% 0%;
transform-origin: 100% 0%
}
h2, h3, h4 { margin: 0; padding: 0 }
.night-tabs .night-tabs-content li .h2,
.night-tabs .night-tabs-content li .h3,
.night-tabs .night-tabs-content li .h4 {
font-weight: 300;
line-height: 1.5
}
.night-tabs .night-tabs-content li .h2 {font-size: 3em}
.night-tabs .night-tabs-content li .h3 {font-size: 2.2em}
.night-tabs .night-tabs-content li .h4 {font-size: 1.4em}
.night-tabs .night-tabs-content li p {
margin: .5em 0;
font-size: 1em
}
.night-tabs .night-tabs-content li a {color: #ecf0f1}
.night-tabs .night-tabs-content li a:hover,
.night-tabs .night-tabs-content li a:focus {text-decoration: none}
.night-tabs .fa { margin-right: .5em }
.night-tabs .night-tabs-content li img {
max-width: 100%;
height: auto
}
.night-tabs .night-tabs-ordered-list,
.night-tabs .night-tabs-unordered-list {
margin-top: .3em;
padding-left: 2.5em
}
.night-tabs .night-tabs-ordered-list {list-style: decimal}
.night-tabs .night-tabs-unordered-list { list-style: disc}
.text-center {text-align: center}
.text-left {text-align: left}
.text-right {text-align: right}
.pull-left {float: left}
.pull-right {float: right}
.dropcap {
font-family: "Sanchez", Rockwell, slab-serif;
float: left;
font-size: 5em;
line-height: .9;
}
.blockquote {
margin: 1em;
padding: 0 0 0 1em;
border-left: 3px solid #ecf0f1
}
.well {
background: #555;
padding: 1em!important
}
.night-tabs .grid-row:after {
content: '';
display: table;
clear: both
}
.night-tabs .grid-row {margin-top: 1em}
.night-tabs .grid-row:first-child {margin-top: 0}
.night-tabs .grid-column {
display: block;
float: left;
width: 100%;
margin-left: 2%
}
.night-tabs .grid-column:first-child { margin-left: 0}
.night-tabs .grid-column-1 {width: 6.5%}
.night-tabs .grid-column-2 {width: 15%}
.night-tabs .grid-column-3 {width: 23.5%}
.night-tabs .grid-column-4 {width: 32%}
.night-tabs .grid-column-5 {width: 40.5%}
.night-tabs .grid-column-6 {width: 49%}
.night-tabs .grid-column-7 {width: 57.5%}
.night-tabs .grid-column-8 {width: 66%}
.night-tabs .grid-column-9 {width: 74.5%}
.night-tabs .grid-column-10 {width: 83%}
.night-tabs .grid-column-11 {width: 91.5%}
.night-tabs .grid-column-offset-1,
.night-tabs .grid-column-offset-1:first-child{margin-left:8.5%}
.night-tabs .grid-column-offset-2,
.night-tabs .grid-column-offset-2:first-child{margin-left:17%}
.night-tabs .grid-column-offset-3,
.night-tabs .grid-column-offset-3:first-child{margin-left:25.5%}
.night-tabs .grid-column-offset-4,
.night-tabs .grid-column-offset-4:first-child{margin-left:34%}
.night-tabs .grid-column-offset-5,
.night-tabs .grid-column-offset-5:first-child{margin-left:42.5%}
.night-tabs .grid-column-offset-6,
.night-tabs .grid-column-offset-6:first-child{margin-left:51%}
.night-tabs .grid-column-offset-7,
.night-tabs .grid-column-offset-7:first-child{margin-left:59.5%}
.night-tabs .grid-column-offset-8,
.night-tabs .grid-column-offset-8:first-child{margin-left:68%}
.night-tabs .grid-column-offset-9,
.night-tabs .grid-column-offset-9:first-child{margin-left:76.5%}
.night-tabs .grid-column-offset-10,.night-tabs .grid-column-offset-10:first-child{margin-left:85%}
.night-tabs .grid-column-offset-11,.night-tabs .grid-column-offset-11:first-child{margin-left:93.5%}
.night-tabs label:hover span span,
.night-tabs input:checked+label span span,
.night-tabs-color-default label:hover span span,
.night-tabs-color-default input:checked+label span span{background: #6c7a89}
.night-tabs-color-blue label:hover span span,
.night-tabs-color-blue input:checked+label span span {background: #1e8bc3}
.night-tabs-color-red label:hover span span,
.night-tabs-color-red input:checked+label span span {background: #ef4836}
.night-tabs-color-green label:hover span span,
.night-tabs-color-green input:checked+label span span {background: #27ae60}
.night-tabs-color-purple label:hover span span,
.night-tabs-color-purple input:checked+label span span {background: #9b59b6}
.night-tabs-color-orange label:hover span span,
.night-tabs-color-orange input:checked+label span span {background: #F9690E}
.night-tabs-color-yellow label:hover span span,
.night-tabs-color-yellow input:checked+label span span {background: #a8880a}
.night-tabs-color-pink label:hover span span,
.night-tabs-color-pink input:checked+label span span {background: #dB0a5b}
.night-tabs-color-brown label:hover span span,
.night-tabs-color-brown input:checked+label span span {background: #926239}
.night-tabs-color-teal label:hover span span,
.night-tabs-color-teal input:checked+label span span {background: #008080}
.night-tabs-color-turquoise label:hover span span,
.night-tabs-color-turquoise input:checked+label span span {background: #16a085}
@media screen and (max-width: 48em) {
.night-tabs .grid-column,
.night-tabs .grid-column:first-child {
float: none;
width: 100%;
margin: 1em 0 0 0
}
.night-tabs > label {
display: block;
float: none;
width: 100%;
padding-right: 0;
padding-left: 0;
text-align: left;
margin: 0
}
.night-tabs > .night-tabs-content {
margin-top: 0;
margin-right: 0;
margin-left: 0
}
.night-tabs > .night-tabs-content > li {
-webkit-transform-origin: 50% 0%;
-ms-transform-origin: 50% 0%;
transform-origin: 50% 0%
}
.night-tabs.night-tabs-animation-flip > ul > li {
-webkit-transform: rotateX(-90deg);
transform: rotateX(-90deg)
}
}
body {
background: #111;
margin-top: 2em
}
总结:
这里主要使用表单的单选按钮来实现这个TAB显示和隐藏,首页tab里的内容默认隐藏,如果单选按钮为选中状态(checked)就显示内容。具体请看下面代码。
关于兼容性,因为是用CSS3来制作的,所以如果不支持CSS3的浏览将会出现不兼容的情况。
到此,关于“如何使用css3实现的tab选项卡”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注编程网网站,小编会继续努力为大家带来更多实用的文章!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341