gpt4 book ai didi

html - 扩展 sidenav 时 CSS Hamburger 不旋转

转载 作者:太空宇宙 更新时间:2023-11-04 01:47:27 27 4
gpt4 key购买 nike

我无法让我的 ccs made hamburger 打开展开/折叠我的 sidenav,最重要的是。如果我让它展开/折叠,它就会停止旋转。请看codepen 演示,感谢反馈

我想我在 css 中犯了一个错误,但我很难追踪这个问题。我真的很感激第二双眼睛。

HTML

<div class="container-fluid">
<div class="row d-flex d-md-block flex-nowrap wrapper">
<div class="col-md-2 float-left col-1 pl-0 pr-0 collapse width show" id="sidebar">
<div class="list-group border-0 card bg-faded text-center text-md-left">
<a class="list-group-item d-inline-block collapsed" data-parent="#sidebar" href="#"><i class="fa fa-heart"></i> <span class="hidden-sm-down">Item 4</span></a>
<a class="list-group-item d-inline-block collapsed" data-parent="#sidebar" href="#"><i class="fa fa-list"></i> <span class="hidden-sm-down">Item 5</span></a>
<a class="list-group-item d-inline-block collapsed" data-parent="#sidebar" href="#"><i class="fa fa-clock-o"></i> <span class="hidden-sm-down">Link</span></a>
</div>
</div>

<main class="col-md-10 float-left col px-5 px-md-3 py-3 main">
<!--<a data-target="#sidebar" data-toggle="collapse" href="#">
a
</a>-->
<div class="outer-menu">
<input data-target="#sidebar" class="checkbox-toggle" data-toggle="collapse" type="checkbox">
<div class="hamburger">
<div>
</div>
</div>
</div>
</main>
<h1 class="display-3 hidden-xs-down">Bootstrap 4 Dashboard</h1>
</div>
</div>

CSS

#sidebar {
overflow: hidden;
z-index: 3;
}
#sidebar .list-group {
min-width: 300px;
min-height: 100vh;
}

#sidebar .list-group-item {
border-radius: 0;
white-space: nowrap;
}

@media (max-width:768px) {
#sidebar {
min-width: 35px;
max-width: 40px;
overflow-y: auto;
overflow-x: visible;
transition: all 0.25s ease;
transform: translateX(-45px);
position: fixed;
}

#sidebar.show {
transform: translateX(0);
}

#sidebar::-webkit-scrollbar{ width: 0px; }

#sidebar, #sidebar .list-group {
min-width: 35px;
overflow: visible;
}
/* overlay sub levels on small screens */
#sidebar .list-group .collapse.show, #sidebar .list-group .collapsing {
position: relative;
z-index: 1;
width: 190px;
top: 0;
}
#sidebar .list-group > .list-group-item {
text-align: center;
padding: .75rem .5rem;
}
/* hide caret icons of top level when collapsed */
#sidebar .list-group > .list-group-item[aria-expanded="true"]::after,
#sidebar .list-group > .list-group-item[aria-expanded="false"]::after {
display:none;
}
}

.collapse.show {
visibility: visible;
}
.collapsing {
visibility: visible;
height: 0;
-webkit-transition-property: height, visibility;
transition-property: height, visibility;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.collapsing.width {
-webkit-transition-property: width, visibility;
transition-property: width, visibility;
width: 0;
height: 100%;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}


/* hamburger */

/*********************/
.outer-menu {
position: relative;
left: 0;
z-index: 1;
}
.outer-menu .checkbox-toggle {
position: absolute;
top: 0;
left: 0;
z-index: 2;
cursor: pointer;
width: 60px;
height: 60px;
opacity: 0;
}
.outer-menu .checkbox-toggle:checked + .hamburger > div {
transform: rotate(135deg);
}
.outer-menu .checkbox-toggle:checked + .hamburger > div:before,
.outer-menu .checkbox-toggle:checked + .hamburger > div:after {
top: 0;
transform: rotate(90deg);
}
.outer-menu .checkbox-toggle:checked + .hamburger > div:after {
opacity: 0;
}
.outer-menu .checkbox-toggle:checked ~ .menu {
pointer-events: auto;
visibility: visible;
}
.outer-menu .checkbox-toggle:checked ~ .menu > div {
transform: scale(1);
transition-duration: .75s;
}
.outer-menu .checkbox-toggle:checked ~ .menu > div > div {
opacity: 1;
transition: opacity 0.4s ease 0.4s;
}
.outer-menu .checkbox-toggle:hover + .hamburger {
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
}
.outer-menu .checkbox-toggle:checked:hover + .hamburger > div {
transform: rotate(225deg);
}
.outer-menu .hamburger {
position: absolute;
top: 0;
left: 0;
z-index: 1;
width: 60px;
height: 60px;
padding: .5em 1em;
background: rgba(33, 150, 243, 0.75);
border-radius: 0 0.12em 0.12em 0;
cursor: pointer;
transition: box-shadow 0.4s ease;
backface-visibility: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.outer-menu .hamburger > div {
position: relative;
flex: none;
width: 100%;
height: 2px;
background: #fefefe;
transition: all 0.4s ease;
display: flex;
align-items: center;
justify-content: center;
}
.outer-menu .hamburger > div:before,
.outer-menu .hamburger > div:after {
content: '';
position: absolute;
z-index: 1;
top: -10px;
left: 0;
width: 100%;
height: 2px;
background: inherit;
transition: all 0.4s ease;
}
.outer-menu .hamburger > div:after {
top: 10px;
}

最佳答案

你的 codepen 不工作,应该先加载 jquery。

无论如何,这是我修复它的尝试。以全屏模式查看。正确加载 jquery 后,您的代码可以正常工作,但旋转效果除外,因为您的选择器错误。

请参阅 CSS 中的 汉堡包X 按钮 部分。

#sidebar {
overflow: hidden;
z-index: 3;
}
#sidebar .list-group {
min-width: 300px;
min-height: 100vh;
}

#sidebar .list-group-item {
border-radius: 0;
white-space: nowrap;
}

@media (max-width:768px) {
#sidebar {
min-width: 35px;
max-width: 40px;
overflow-y: auto;
overflow-x: visible;
transition: all 0.25s ease;
transform: translateX(-45px);
position: fixed;
}

#sidebar.show {
transform: translateX(0);
}

#sidebar::-webkit-scrollbar{ width: 0px; }

#sidebar, #sidebar .list-group {
min-width: 35px;
overflow: visible;
}
/* overlay sub levels on small screens */
#sidebar .list-group .collapse.show, #sidebar .list-group .collapsing {
position: relative;
z-index: 1;
width: 190px;
top: 0;
}
#sidebar .list-group > .list-group-item {
text-align: center;
padding: .75rem .5rem;
}
/* hide caret icons of top level when collapsed */
#sidebar .list-group > .list-group-item[aria-expanded="true"]::after,
#sidebar .list-group > .list-group-item[aria-expanded="false"]::after {
display:none;
}
}

.collapse.show {
visibility: visible;
}
.collapsing {
visibility: visible;
height: 0;
-webkit-transition-property: height, visibility;
transition-property: height, visibility;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}
.collapsing.width {
-webkit-transition-property: width, visibility;
transition-property: width, visibility;
width: 0;
height: 100%;
-webkit-transition-timing-function: ease-out;
transition-timing-function: ease-out;
}


/* hamburger */

/*********************/
.outer-menu {
position: relative;
left: 0;
z-index: 1;
}
.outer-menu .checkbox-toggle {
position: absolute;
top: 0;
left: 0;
z-index: 2;
cursor: pointer;
width: 60px;
height: 60px;
opacity: 0;
}
.outer-menu .hamburger {
position: absolute;
top: 0;
left: 0;
z-index: 1;
width: 60px;
height: 60px;
padding: .5em 1em;
background: rgba(33, 150, 243, 0.75);
border-radius: 0 0.12em 0.12em 0;
cursor: pointer;
transition: box-shadow 0.4s ease;
backface-visibility: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.outer-menu .hamburger > div {
position: relative;
flex: none;
width: 100%;
height: 2px;
background: #fefefe;
transition: all 0.4s ease;
display: flex;
align-items: center;
justify-content: center;
}
.outer-menu .checkbox-toggle.collapsed ~ .hamburger > div {
transform: rotate(0deg);
}

.outer-menu .checkbox-toggle + .hamburger > div:before,
.outer-menu .checkbox-toggle + .hamburger > div:after {
content: '';
position: absolute;
z-index: 1;
top: 0;
left: 0;
width: 100%;
height: 2px;
background: inherit;
transition: all 0.4s ease;
}
.outer-menu .checkbox-toggle.collapsed + .hamburger > div:before {
top: -10px;
}
.outer-menu .checkbox-toggle.collapsed + .hamburger > div:before,
.outer-menu .checkbox-toggle.collapsed + .hamburger > div:after {
transform: rotate(0deg);
opacity: 1;
}
.outer-menu .checkbox-toggle.collapsed + .hamburger > div:after {
top: 10px;
}
/* X button */

.outer-menu .checkbox-toggle + .hamburger > div {
transform: rotate(135deg);
}
.outer-menu .checkbox-toggle + .hamburger > div:before,
.outer-menu .checkbox-toggle + .hamburger > div:after {
top: 0;
transform: rotate(90deg);
}
.outer-menu .checkbox-toggle + .hamburger > div:after {
opacity: 0;
}
.outer-menu .checkbox-toggle ~ .menu {
pointer-events: auto;
visibility: visible;
}
.outer-menu .checkbox-toggle ~ .menu > div {
transform: scale(1);
transition-duration: .75s;
}
.outer-menu .checkbox-toggle ~ .menu > div > div {
opacity: 1;
transition: opacity 0.4s ease 0.4s;
}
.outer-menu .checkbox-toggle:hover + .hamburger {
box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.1);
}
.outer-menu .checkbox-toggle.collapsed:hover + .hamburger > div {
transform: rotate(180deg);
}
.outer-menu .checkbox-toggle:hover + .hamburger > div {
transform: rotate(225deg);
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>
<div class="container-fluid">
<div class="row d-flex d-md-block flex-nowrap wrapper">
<div class="col-md-2 float-left col-1 pl-0 pr-0 collapse width collapse" id="sidebar">
<div class="list-group border-0 card bg-faded text-center text-md-left">
<a class="list-group-item d-inline-block collapsed" data-parent="#sidebar" href="#"><i class="fa fa-heart"></i> <span class="hidden-sm-down">Item 4</span></a>
<a class="list-group-item d-inline-block collapsed" data-parent="#sidebar" href="#"><i class="fa fa-list"></i> <span class="hidden-sm-down">Item 5</span></a>
<a class="list-group-item d-inline-block collapsed" data-parent="#sidebar" href="#"><i class="fa fa-clock-o"></i> <span class="hidden-sm-down">Link</span></a>
</div>
</div>

<main class="col-md-10 float-left col px-5 px-md-3 py-3 main">
<!--<a data-target="#sidebar" data-toggle="collapse" href="#">
a
</a>-->
<div class="outer-menu">
<input data-target="#sidebar" class="checkbox-toggle collapsed" data-toggle="collapse" type="checkbox">
<div class="hamburger">
<div>
</div>
</div>
</div>
</main>
<h1 class="display-3 hidden-xs-down">Bootstrap 4 Dashboard</h1>
</div>
</div>

关于html - 扩展 sidenav 时 CSS Hamburger 不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44193524/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com