<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.tab-navbar {
display: flex;
overflow: hidden;
flex-direction: column-reverse;
border-radius: 10px;
width: 300px;
height: 400px;
}
.tab-navbar input {
display: none;
}
.tab-navbar input:nth-child(1):checked ~ main ul {
background-color: #f66;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.tab-navbar input:nth-child(2):checked ~ main ul {
background-color: #66f;
-webkit-transform: translate3d(-25%, 0, 0);
transform: translate3d(-25%, 0, 0);
}
.tab-navbar input:nth-child(3):checked ~ main ul {
background-color: #f90;
-webkit-transform: translate3d(-50%, 0, 0);
transform: translate3d(-50%, 0, 0);
}
.tab-navbar input:nth-child(4):checked ~ main ul {
background-color: #09f;
-webkit-transform: translate3d(-75%, 0, 0);
transform: translate3d(-75%, 0, 0);
}
.tab-navbar nav {
display: flex;
height: 40px;
background-color: #f0f0f0;
line-height: 40px;
text-align: center;
}
.tab-navbar nav label {
flex: 1;
cursor: pointer;
transition: all 300ms;
}
.tab-navbar main {
flex: 1;
}
.tab-navbar main ul {
display: flex;
flex-wrap: nowrap;
width: 400%;
height: 100%;
transition: all 300ms;
}
.tab-navbar main li {
display: flex;
justify-content: center;
align-items: center;
flex: 1;
font-weight: bold;
font-size: 20px;
color: #fff;
}
.active, .tab-navbar input:nth-child(1):checked ~ nav label:nth-child(1), .tab-navbar input:nth-child(2):checked ~ nav label:nth-child(2), .tab-navbar input:nth-child(3):checked ~ nav label:nth-child(3), .tab-navbar input:nth-child(4):checked ~ nav label:nth-child(4) {
background-color: #3c9;
color: #fff;
}
</style>
</head>
<body>
<p>
要点:可切换内容的导航栏<br>
场景:页面切换
</p>
<div class="bruce flex-ct-x">
<div class="tab-navbar">
<input type="radio" name="tab" id="tab1" checked>
<input type="radio" name="tab" id="tab2">
<input type="radio" name="tab" id="tab3">
<input type="radio" name="tab" id="tab4">
<nav>
<label for="tab1">标题1</label>
<label for="tab2">标题2</label>
<label for="tab3">标题3</label>
<label for="tab4">标题4</label>
</nav>
<main>
<ul>
<li>内容1</li>
<li>内容2</li>
<li>内容3</li>
<li>内容4</li>
</ul>
</main>
</div>
</div>
</body>
</html>
2021-08-13 css-js-炫酷的原生选项卡切换
最新推荐文章于 2024-09-02 11:46:47 发布