[英]hamburger menu not working with styled components
I'm really confused why it is not working. 我真的很困惑为什么它不起作用。 I am using styled-components library and actually I've got a problem with hamburger menu.
我正在使用样式组件库,实际上我的汉堡菜单有问题。 It changes only when the checkbox is shown.
仅在显示复选框时,它才会更改。 It should work with only css but its not do have any suggestions?
它应该只能与CSS一起使用,但没有任何建议吗?
const HamburgerCnt = styled.div`
cursor: pointer;
position: absolute;
top: 35px;
right: 41px;
height: 28px;
width: 30px;
input {
display: none;
}
input + label {
position: absolute;
top: 12px;
right: 0px;
width: 30px;
height: 2px;
background: #fff;
display: block;
transform-origin: center;
transition: .5s ease-in-out;
&:after,
&:before {
transition: .5s ease-in-out;
content: "";
position: absolute;
display: block;
width: 100%;
height: 100%;
background: #fff;
}
&:before {
top: -10px;
}
&:after {
bottom: -10px;
}
}
input:checked + label {
transform: rotate(45deg);
&:after {
transform: rotate(90deg);
bottom: 0;
}
&:before {
transform: rotate(90deg);
top: 0;
}
}
`;
and Component looks like this 组件看起来像这样
<HamburgerCnt>
<input type="checkbox" name="check" />
<label htmlFor="check" />
</HamburgerCnt>
You should use check
as id
of the input, not its name. 您应该使用
check
作为输入的id
,而不是其名称。
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#Using_the_for_attribute https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#Using_the_for_attribute
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.