Не могу выровнять элемент. Как исправить?
Пытаюсь сделать иконку для гамбургер-меню и выровнять ее с помощью флексов. Но не выходит: иконка уходит куда-то вправо, появляется непонятный отступ сверху.
Вот код:
* {
margin: 0;
padding: 0;
}
input {
display: none;
}
.wrapper {
display: flex;
align-items: center;
justify-content: flex-end;
position: relative;
width: 100%;
height: 100px;
background: lightblue;
}
span {
position: absolute;
z-index: 1;
width: 70px;
height: 5px;
background: #000;
display: block;
}
span:nth-child(1) {
top: 0px;
}
span:nth-child(2) {
top: 30px;
}
span:nth-child(3) {
top: 60px;
}
label {
background: red;
position: relative;
display: block;
}
<div class="wrapper">
<input type="checkbox" id="click">
<label for="click">
<span></span>
<span></span>
<span></span>
</label>
</div>
Также не совсем понятно почему label не видит своих потомков (родитель с position: relative/fixed/absolute по идее же должен видеть своих потомков с абсолютным позиционированием).
В чем тут может быть дело?
Ответы (1 шт):
Автор решения: Sparklingman
→ Ссылка
* {
margin: 0;
padding: 0;
}
.wrapper {
display: flex;
align-items: center;
justify-content: flex-end;
position: relative;
width: 100%;
height: 100px;
background: lightblue;
}
label {
cursor: pointer;
position: relative;
z-index: 1;
width: 70px;
height: 70px;
display: block;
right: 20px;
}
[type="checkbox"] {
opacity: 0;
position: fixed;
}
span,
span:after,
span:before {
background: #000;
display: block;
height: 5px;
position: absolute;
right: 0;
transition: .1s linear;
width: 70px;
}
span {
margin: -2.5px 0 0;
top: 50%;
}
span:after {
content: '';
top: 20px;
}
span:before {
content: '';
top: -20px;
}
[type="checkbox"]:checked+span {
background: transparent;
}
[type="checkbox"]:checked+span:after {
transform: rotate(45deg);
top: 0;
}
[type="checkbox"]:checked+span:before {
transform: rotate(-45deg);
top: 0;
}
<div class="wrapper">
<label>
<input type="checkbox">
<span></span>
</label>
</div>