<section class="wrapper">
<input type="radio" name="tabs" id="tab1" hidden checked>
<input type="radio" name="tabs" id="tab2" hidden>
<input type="radio" name="tabs" id="tab3" hidden>
<input type="radio" name="tabs" id="tab4" hidden>
<div class="navs">
<label for="tab1">标题01</label>
<label for="tab2">标题02</label>
<label for="tab3">标题03</label>
<label for="tab4">标题04</label>
</div>
<ul class="views">
<li>内容01</li>
<li>内容02</li>
<li>内容03</li>
<li>内容04</li>
</ul>
</section>
body {
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
.wrapper {
flex-shrink: 0;
width: 300px;
height: 340px;
display: flex;
flex-flow: column wrap;
border-radius: 8px;
overflow: hidden;
}
.navs {
order: 1;
flex-shrink: 0;
height: 40px;
display: inline-flex;
}
.navs label {
flex: 1;
background: #eee;
text-align: center;
line-height: 40px;
cursor: pointer;
font-size: 12px;
}
.views {
flex: 1;
width: 100%;
margin: 0;
padding: 0;
white-space: nowrap;
font-size: 0;
transition: transform 200ms linear;
}
.views li {
display: inline-flex;
width: 100%;
height: 100%;
font-size: 30px;
align-items: center;
justify-content: center;
}
.views li:nth-child(1) {
background-color:tomato;
}
.views li:nth-child(2) {
background-color:yellowgreen;
}
.views li:nth-child(3) {
background-color:darkviolet;
}
.views li:nth-child(4) {
background-color:darkorange;
}
input:nth-child(1):checked ~ .navs label:nth-child(1),
input:nth-child(2):checked ~ .navs label:nth-child(2),
input:nth-child(3):checked ~ .navs label:nth-child(3),
input:nth-child(4):checked ~ .navs label:nth-child(4) {
background: skyblue;
}
input:nth-child(1):checked ~ .views {
transform: translate3d(0, 0, 0);
}
input:nth-child(2):checked ~ .views {
transform: translate3d(-100%, 0, 0);
}
input:nth-child(3):checked ~ .views {
transform: translate3d(-200%, 0, 0);
}
input:nth-child(4):checked ~ .views {
transform: translate3d(-300%, 0, 0);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.