使用 :checked 实现

原理:
:checked 和 后代选择器 ~ 实现内容和按钮的显示隐藏DOCTYPE html>
<html>
<head>
<title>checkbox控制显示隐藏title>
head>
<body>
<input id="myCheckbox" type="checkbox" />
<div class="Btn show">
<label for="myCheckbox">显示label>
div>
<div class="Btn hide">
<label for="myCheckbox">隐藏label>
div>
<div class="content">内容div>
<style>
.Btn {
width: 60px;
text-align: center;
border: solid 1px black;
padding: 4px;
border-radius: 4px;
}
label {
display: block;
width: 100%;
cursor: pointer;
}
#myCheckbox {
display: none;
}
.content {
display: none;
}
.hide {
display: none;
}
#myCheckbox:checked ~ .content {
display: block;
}
#myCheckbox:checked ~ .hide {
display: block;
}
#myCheckbox:checked ~ .show {
display: none;
}
style>
body>
html>
使用 :target 实现
可模拟 tab 页签切换效果

原理:
DOCTYPE html>
<html>
<head>
<title>:target模拟页签切换title>
head>
<body>
<a class="tabBtn" href="#p1">第1页a>
<a href="#p2">第2页a>
<a href="#p3">第3页a>
<div class="content" id="p1">第1页的内容div>
<div class="content" id="p2">第2页的内容div>
<div class="content" id="p3">第3页的内容div>
<style>
.content {
display: none;
}
#p1:target {
display: block;
}
#p2:target {
display: block;
}
#p3:target {
display: block;
}
style>
body>
html>