Почему не подключается @media
Пытаюсь сделать шаблон для бургер-меню, не понимаю почему не подключается @media
*,
*:before,
*:after {
padding: 0;
margin: 0;
border: 0;
box-sizing: border-box;
}
html.body {
height: 100%;
font-family: Arial, Helvetica, sans-serif;
}
.wrapper {
padding: 0;
}
.container {
max-width: 1180px;
margin: 0 auto;
padding: 0 10px;
}
.header {
position: fixed;
width: 100%;
top: 0;
left: 0;
z-index: 50;
}
.header:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #0469;
}
.header__body {
position: relative;
z-index: 2;
display: flex;
justify-content: space-between;
height: 80px;
align-items: center;
}
.header__burger {
display: none;
}
.header__menu {
padding: 0;
}
.header__list {
display: flex;
}
.header__list-style {
list-style: none;
margin: 0 0 0 20px;
}
.header__logo-img {
max-width: 100%;
display: block;
}
.header__logo {
flex: 0 0 60px;
border-radius: 50%;
overflow: hidden;
}
.header__link {
color: #fff;
text-transform: uppercase;
font-size: 18px;
text-decoration: none;
}
.content {
padding: 100px 0 0 0;
}
.content__text {
font-size: 16px;
line-height: 1.5;
}
@media (max-width: 768px) {
.header__burger {
display: block;
position: relative;
width: 30px;
height: 20px;
}
.header__burger-span {
position: absolute;
background-color: #fff;
left: 0;
width: 100%;
height: 2px;
top: 9px;
}
.header__burger:before {
content: "";
background-color: #fff;
position: absolute;
width: 100%;
height: 2px;
left: 0;
top: 0;
}
.header__burger:after {
content: "";
background-color: #fff;
position: absolute;
width: 100%;
height: 2px;
left: 0;
bottom: 0;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="index.css">
<title>Document</title>
</head>
<body>
<div class="wrapper">
<header class="header">
<div class="container">
<div class="header__body">
<a href="#" class="header__logo">
<img src="#" alt="" class="header__logo-img">
</a>
<div class="header__burger">
<span class="header__burger-span"></span>
</div>
<nav class="header__menu">
<ul class="header__list">
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
</ul>
</nav>
</div>
</div>
</header>
<div class="content">
<div class="container">
<div class="content__text">
<p>
reprehenderit beatae ea cumque explicabo tenetur maxime doloribus sit qui. Soluta, vel porro.
</p>
<p>
s, cumque quaerat vel unde velit temporibus quisquam iure saepe praesentium! Aut ut reprehenderit beatae ea cumque explicabo tenetur maxime doloribus sit qui. Soluta, vel porro.
</p>
</div>
</div>
</div>
</div>
</body>
</html>
Ответы (1 шт):
Автор решения: Django Student
→ Ссылка
У вас всё отлично работает. Просто вы поставили на .header__burger width:30px и height:20px но эти коды зачем то не работают. Самый простой способ избежать от проблем это поставить Padding! Я поставил вот так:
*,
*:before,
*:after {
padding: 0;
margin: 0;
border: 0;
box-sizing: border-box;
}
body {
height: 100%;
font-family: Arial, Helvetica, sans-serif;
}
.wrapper {
padding: 0;
}
.container {
max-width: 1180px;
margin: 0 auto;
padding: 0 10px;
}
.header {
position: fixed;
width: 100%;
top: 0;
left: 0;
z-index: 50;
}
.header:before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #0469;
}
.header__body {
position: relative;
z-index: 2;
display: flex;
justify-content: space-between;
height: 80px;
align-items: center;
}
.header__burger {
display: none;
}
.header__menu {
padding: 0;
}
.header__list {
display: flex;
}
.header__list-style {
list-style: none;
margin: 0 0 0 20px;
}
.header__logo-img {
max-width: 100%;
display: block;
}
.header__logo {
flex: 0 0 60px;
border-radius: 50%;
overflow: hidden;
}
.header__link {
color: #fff;
text-transform: uppercase;
font-size: 18px;
text-decoration: none;
}
.content {
padding: 100px 0 0 0;
}
.content__text {
font-size: 16px;
line-height: 1.5;
}
@media (max-width: 768px) {
.header__burger {
display: block;
position: relative;
padding: 10px 15px /* ////////////////////////////////////////////////// */
}
.header__burger-span {
position: absolute;
background-color: #fff;
left: 0;
width: 100%;
height: 2px;
top: 9px;
}
.header__burger:before {
content: "";
background-color: #fff;
position: absolute;
width: 100%;
height: 2px;
left: 0;
top: 0;
}
.header__burger:after {
content: "";
background-color: #fff;
position: absolute;
width: 100%;
height: 2px;
left: 0;
bottom: 0;
}
}
<div class="wrapper">
<header class="header">
<div class="container">
<div class="header__body">
<a href="#" class="header__logo">
<img src="#" alt="" class="header__logo-img">
</a>
<div class="header__burger">
<span class="header__burger-span"></span>
</div>
<nav class="header__menu">
<ul class="header__list">
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
<li class="header__list-style">
<a href="" class="header__link">Главная</a>
</li>
</ul>
</nav>
</div>
</div>
</header>
<div class="content">
<div class="container">
<div class="content__text">
<p>
reprehenderit beatae ea cumque explicabo tenetur maxime doloribus sit qui. Soluta, vel porro.
</p>
<p>
s, cumque quaerat vel unde velit temporibus quisquam iure saepe praesentium! Aut ut reprehenderit beatae ea cumque explicabo tenetur maxime doloribus sit qui. Soluta, vel porro.
</p>
</div>
</div>
</div>
</div>