1.先搭结构和样式
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>选项卡</title>
<style>
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
.box {
width: 500px;
margin: 20px auto;
}
.box .tab {
display: flex;
justify-content: flex-start;
align-items: center;
position: relative;
top: 1px;
}
.box .tab li {
box-sizing: border-box;
padding: 0 25px;
margin-right: 15px;
height: 35px;
line-height: 33px;
border: 1px solid #ccc;
background: #ddd;
color: #555;
font-size: 14px;
cursor: pointer;
}
.box .tab li.active {
background: #fff;
font-weight: 700;
border-bottom-color: #fff;
}
.box .content div {
display: none;
box-sizing: border-box;
padding: 15px;
height: 200px;
border: 1px solid #ccc;
}
.box .content div.active {
display: block;