写页面的时候,发现 display:none;不生效。
用了!important 才管用,搜那个优先级,没搜到。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- <link rel="stylesheet" href="./index.css"> -->
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background-color: #000;
}
ul {
list-style: none;
}
a {
text-decoration: none;
}
.header {
height: 50px;
background-color: #1E1E1E;
}
.header-box {
height: 50px;
width: 900px;
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 auto;
}
.header-box .header-box-nav {
display: flex;
}
.header-box .header-box-nav li {
margin: 0 30px;
}
.header-box-nav li a {
color: rgba(255, 255, 255, .5);
transition: 0.3s;
}
.header-box-nav li:hover a {
color: white;
}
.logo {
font-size: 24px;
color: rgba(255, 255, 255, .5);
font-family: 'Courier New', Courier, monospace;
margin-left: 10px;
}
@media(max-width:970px) {
.header-box {
max-width: 100%;
}
}
@media(max-width:640px) {
.header-box {
position: relative;
}
.header-box-nav {
position: absolute;
top: 50px;
left: 0;
bottom: 0;
width: 250px;
height: calc(100vh - 50px);
background-color: #1E1E1E;
flex-direction: column;
align-items: center;
}
.header-box-nav li {
width: 250px;
height: 60px;
line-height: 60px;
text-align: center;
transition: 0.3s;
}
.header-box-nav li:hover {
background-color: #8d8984de;
}
/* 汉堡按钮样式 */
.header-box .sidebar div {
width: 20px;
height: 2px;
background-color: white;
margin: 5px 20px;
}
.header-box .sidebar:hover {
cursor: pointer;
}
/* 给侧边导航栏先 display:none 不生效 */
.header-box-nav {
display: none;
}
}
</style>
</head>
<body>
<!-- 头部导航栏 -->
<div class="header">
<div class="header-box">
<div class="logo">小代前端</div>
<ul class="header-box-nav">
<li><a href="#">首页</a></li>
<li><a href="#">案例</a></li>
<li><a href="#">服务</a></li>
<li><a href="#">关于我们</a></li>
<li><a href="#">新闻资讯</a></li>
</ul>
<div class="sidebar">
<div class="top-line"></div>
<div class="center-line"></div>
<div class="bottom-line"></div>
</div>
</div>
</div>
</body>
</html>