gpt4 book ai didi

html - CSS - 可见性问题 : hidden; on Dropmenu

转载 作者:行者123 更新时间:2023-11-28 14:43:37 25 4
gpt4 key购买 nike

ul.ulDropMenu{
z-index: 2;
}
ul.ulDropMenu li{
list-style: none;
position: relative;
}
ul.ulDropMenu li ul li a:hover{
color: #ff003c;
}
ul.ulDropMenu li a{
display: block;
padding: 9px 14px;
}
ul.ulDropMenu li ul{
position: absolute;
background-color: #fff;
border-radius: 4px;
padding: 8px;
}
nav ul li ul{
visibility: hidden;
display: block;
}
ul.ulDropMenu li:hover ul{
max-height: 290px;
visibility: visible;
opacity: 1;
}
ul.ulDropMenu li ul li{
width: 135px;
}

ul.ulDropMenu li ul li a{
padding: 6px 14px;
color: #2A2A2A;
}

.navBar {
background-color: #2A2A2A;
min-width: 100%;
}
.wrapper {
max-width: 100%;
padding: 0 10px;
-webkit-box-shadow: 0px 2px 7px 3px #8C8C8C;
-moz-box-shadow: 0px 2px 7px 3px #8C8C8C;
box-shadow: 0px 2px 7px 3px #8C8C8C;
padding-top: 3px;
}
nav ul {
display: flex;
justify-content: space-between;
list-style-type: none;
padding-top: 15px;
}
nav ul a {
color: #7f7f7f;
text-decoration: none;
transition: color .4s ease;
font-size: 18px;
}
nav ul li ul li a{
font-size: 15px;
}
nav ul a:hover {
color: #afafaf;
}
nav li {
display: inline-block;
}
nav #menu-toggle {
display: none;
}
nav .label-toggle {
display: none;
}
nav .wrapper {
align-items: center;
display: flex;
}
@media screen and (max-width: 992px) {
nav nav ul li ul li {
color: #7f7f7f;
padding-right: 20px;
}
nav ul {
display: block;
height: 0;
list-style-type: none;
opacity: 0;
text-align: left;
padding-left: 0;
transition: all 1s ease;
width: 50%;
visibility: hidden;
}
nav li {
color: #53354A;
display: block;
font-size: 19px;
}
nav #menu-toggle:checked ~ ul {
opacity: 1;
height: 62vh;
visibility: visible;
}
nav .label-toggle {
background: linear-gradient(to bottom, #fff 0%, #fff 20%, transparent 20%, transparent 40%, #fff 40%, #fff 60%, transparent 60%, transparent 80%, #fff 80%, #fff 100%);
cursor: pointer;
display: block;
float: right;
height: 35px;
margin-top: 35px;
width: 35px;
}
nav .wrapper {
display: block;
}
}
<nav class="navBar">
<nav class="wrapper">
<a href=""><img width="215" height="85" src="https://www.dsgfs.com/wp-content/uploads/2015/09/Test-Logo-250x60.png" alt=""></a>
<input type="checkbox" id="menu-toggle" />
<label for="menu-toggle" class="label-toggle"></label>
<ul class="ulDropMenu">
<li>
<a href="">Menu 1</a>
</li>
<li>
<a href="#">Menu 2
<i class="fa fa-caret-down"></i>
</a>
<ul>
<li>
<a href="">1</a>
</li>
<li>
<a href="">2</a>
</li>
</ul>
</li>
<li>
<a href="#">Menu 3
<i class="fa fa-caret-down"></i>
</a>
<ul>
<li>
<a href="" target="_blank"><i class="fab fa-facebook-square"></i> Facebook</a>
<a href="" target="_blank"><i class="fab fa-twitter-square"></i> Twitter</a>
<a href="" target="_blank"><i class="fab fa-instagram"></i> Instagram</a>
</li>
</ul>
</li>
</ul>
</nav>
</nav>

Click on "Run code snipped" and on "full page" to see the snipped, and resize the screen under 992px.

当我将屏幕尺寸调整到 992px 以下时,问题就开始了。 navbar 在底部变大,dropmenu 打不开,我认为这可能是 display: block 的错误,但我不认为这是。我在这里做了一些测试,我意识到这个问题是由这一行引起的:

nav ul {
display: block;
height: 0;
list-style-type: none;
opacity: 0;
text-align: left;
padding-left: 0;
transition: all 1s ease;
width: 50%;
visibility: hidden; //This line
}

但是如果我去掉 visibility: hidden;,我的可折叠菜单将不起作用。

我该如何解决?

enter image description here

最佳答案

你的 CSS 很乱。导航栏上有不需要的空间,因为 ul.ulDropMenu 始终可见,并且它具有 padding-top: 15px 继承自 .nav ul 和继承的边距从默认浏览器设置。我建议你read first about resets

/* basic reset for all elements */
* {
margin: 0;
padding: 0;
border: 0;
}

ul.ulDropMenu{
z-index: 2;
padding: 0; /* override padding set by '.nav ul' */
}
ul.ulDropMenu li{
list-style: none;
position: relative;
}
ul.ulDropMenu li ul li a:hover{
color: #ff003c;
}
ul.ulDropMenu li a{
display: block;
padding: 9px 14px;
}
ul.ulDropMenu li ul{
position: absolute;
background-color: #fff;
border-radius: 4px;
padding: 8px;
height: auto; /* override height set in '.nav ul' */
}
nav ul li ul{
visibility: hidden;
display: block;
}
ul.ulDropMenu li:hover ul{
max-height: 290px;
visibility: visible;
opacity: 1;
z-index: 1;
}
ul.ulDropMenu li ul li{
width: 135px;
}

ul.ulDropMenu li ul li a{
padding: 6px 14px;
color: #2A2A2A;
}

.navBar {
background-color: #2A2A2A;
min-width: 100%;
}
.wrapper {
max-width: 100%;
padding: 0 10px;
-webkit-box-shadow: 0px 2px 7px 3px #8C8C8C;
-moz-box-shadow: 0px 2px 7px 3px #8C8C8C;
box-shadow: 0px 2px 7px 3px #8C8C8C;
padding-top: 3px;
}
nav ul {
display: flex;
justify-content: space-between;
list-style-type: none;
padding-top: 15px;
}
nav ul a {
color: #7f7f7f;
text-decoration: none;
transition: color .4s ease;
font-size: 18px;
}
nav ul li ul li a{
font-size: 15px;
}
nav ul a:hover {
color: #afafaf;
}
nav li {
display: inline-block;
}
nav #menu-toggle {
display: none;
}
nav .label-toggle {
display: none;
}
nav .wrapper {
align-items: center;
display: flex;
}
@media screen and (max-width: 992px) {
nav nav ul li ul li {
color: #7f7f7f;
padding-right: 20px;
}
nav ul {
display: block;
height: 0;
list-style-type: none;
opacity: 0;
text-align: left;
padding-left: 0;
transition: all 1s ease;
width: 50%;
visibility: hidden;
}
nav li {
color: #53354A;
display: block;
font-size: 19px;
}
nav #menu-toggle:checked ~ ul {
opacity: 1;
height: 62vh;
visibility: visible;
}
nav .label-toggle {
background: linear-gradient(to bottom, #fff 0%, #fff 20%, transparent 20%, transparent 40%, #fff 40%, #fff 60%, transparent 60%, transparent 80%, #fff 80%, #fff 100%);
cursor: pointer;
display: block;
float: right;
height: 35px;
margin-top: 35px;
width: 35px;
}
nav .wrapper {
display: block;
}
}
<nav class="navBar">
<nav class="wrapper">
<a href=""><img width="215" height="85" src="https://www.dsgfs.com/wp-content/uploads/2015/09/Test-Logo-250x60.png" alt=""></a>
<input type="checkbox" id="menu-toggle" />
<label for="menu-toggle" class="label-toggle"></label>
<ul class="ulDropMenu">
<li>
<a href="">Menu 1</a>
</li>
<li>
<a href="#">Menu 2
<i class="fa fa-caret-down"></i>
</a>
<ul>
<li>
<a href="">1</a>
</li>
<li>
<a href="">2</a>
</li>
</ul>
</li>
<li>
<a href="#">Menu 3
<i class="fa fa-caret-down"></i>
</a>
<ul>
<li>
<a href="" target="_blank"><i class="fab fa-facebook-square"></i> Facebook</a>
<a href="" target="_blank"><i class="fab fa-twitter-square"></i> Twitter</a>
<a href="" target="_blank"><i class="fab fa-instagram"></i> Instagram</a>
</li>
</ul>
</li>
</ul>
</nav>
</nav>

关于html - CSS - 可见性问题 : hidden; on Dropmenu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52573065/

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