(我对 HTML 和 CSS 还不太熟悉,所以请耐心听我说)我一直在尝试自定义这个网站,让它看起来更美观。我想做的一件事是自定义“浏览”和“提交”下的下拉菜单,这样当你将鼠标悬停在它们上面时,它们会平滑地向下延伸,就像一个向下滑动的效果。我想同时为下拉菜单本身和里面的文本制作动画。
我正在查看的 HTML 片段是这样的:
.dropdown-toggle {
min-height: fit-content;
min-width: fit-content;
max-height: fit-content;
max-width: fit-content;
}
.dropdown-menu {
block-size: fit-content;
width: 100px;
height: 200px;
transition: height 1s;
overflow: hidden;
}
.dropdown-menu:hover {
height: 300px;
block-size: fit-content;
overflow: hidden;
}
.nav-item dropdown {
width: 100px;
height: 100px;
transition: height 2s;
block-size: fit-content;
overflow: hidden;
}
.nav-item dropdown:hover {
height: 300px;
block-size: fit-content;
overflow: hidden;
}
.nav-link dropdown-toggle {
width: 100px;
height: 100px;
transition: height 1s;
overflow: hidden;
}
.nav-link dropdown-toggle:hover {
height: 300px;
}
.dropdown-item {
width: 30px;
height: 30px;
transition: height 1s;
position: sticky;
}
.dropdown-item:hover {
height: 50px;
}
.dropdown-menu show {
min-height: 0px;
min-width: 0px;
max-height: 300px;
max-width: 300px;
}
.dropdown-menu show:hover {
height: 50px;
}
<!-- Left Nav Section -->
<ul class="navbar-nav mr-auto navbar-left">
<li class="nav-item">
<a class="nav-link" href="https://toyhou.se/DeclineOfMySanity">
<span class="fa fa-home"></span> Profile
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://toyhou.se/~forums">
<span class="fa fa-comments"></span> Forums
</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" data-target="#dropdownBrowse" >
<span class="fa fa-fw fa-search"></span>
Browse
</a>
<div class="dropdown-menu" id="dropdownBrowse">
<h6 class="dropdown-header">Characters</h6>
<a class="dropdown-item" href="https://toyhou.se/~browse/popular"><i class="fa fa-fire fa-fw mr-1"></i> Popular </a>
<a class="dropdown-item" href="https://toyhou.se/~browse/feed"><i class="fa fa-binoculars fa-fw mr-1"></i> Feed </a>
<a class="dropdown-item" href="https://toyhou.se/~browse/recent"><i class="fa fa-fw fa-clock mr-1"></i> Recent </a>
<a class="dropdown-item" href="https://toyhou.se/~browse/search"><i class="fa fa-fw fa-search mr-1"></i> Search </a>
<h6 class="dropdown-header">Browse</h6>
<a class="dropdown-item" href="https://toyhou.se/~library/popular"><i class="fa fa-fw fa-book mr-1"></i> Literatures </a>
<a class="dropdown-item" href="https://toyhou.se/~worlds"><i class="fa fa-fw fa-globe mr-1"></i> Worlds </a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" data-target="#dropdownCreate" > <span class="fa fa-fw fa-plus"></span> Submit </a>
<div class="dropdown-menu" id="dropdownCreate">
<a class="dropdown-item" href="https://toyhou.se/~characters/create"><i class="fa fa-fw fa-user mr-1"></i> Character </a>
<a class="dropdown-item" href="https://toyhou.se/~bulletins/create"><i class="fa fa-fw fa-newspaper mr-1"></i> Bulletin </a>
<a class="dropdown-item" href="https://toyhou.se/~images/upload"><i class="fa fa-fw fa-image mr-1"></i> Image </a>
<a class="dropdown-item" href="https://toyhou.se/~images/multi-upload"><i class="fa fa-fw fa-image mr-1"></i> Multi-Images </a>
<a class="dropdown-item" href="https://toyhou.se/~literatures/create"><i class="fa fa-fw fa-book mr-1"></i> Literature </a>
<a class="dropdown-item" href="https://toyhou.se/~worlds/create"><i class="fa fa-fw fa-globe mr-1"></i> World </a>
</div>
</li>
</ul>
我已经自己尝试了一些方法,并且到目前为止已经将其应用到我的 CSS 中:
老实说,这些只是让它移动的一系列尝试。我看到的问题包括下拉菜单仅在悬停在框本身上时才会扩展,而不是在“提交”按钮上扩展,文本后面的块在悬停时立即显示,而不是从无到有滑出,并且无法使文本后面的块自行扩展;无论我做什么,它都会弹出。
说实话我真的很困惑所以如果能提供任何帮助我将非常感激!
确保下拉菜单默认隐藏
悬停时显示下拉菜单
为动画添加一点延迟以获得更流畅的效果
确保下拉菜单在鼠标悬停时保持可见
我希望这对你有帮助