gpt4 book ai didi

html - 导航下拉菜单 CSS

转载 作者:太空宇宙 更新时间:2023-11-04 06:45:31 25 4
gpt4 key购买 nike

我试图将导航定位在标题区域中间的右侧。喜欢cyberchimps

enter image description here

此外,当我将鼠标悬停在 BGA 的子菜单上时,我想为 BGA 保持悬停状态。我不确定如何完成此操作。

我在几个例子中看到了 CSS 中的“*”,今天使用它是一个好习惯吗?

我怀疑我的方法是否合理,欢迎提出任何建议。

@charset "utf-8";
/* CSS Document */
body{
margin: 0;
padding: 0;
background-color: #CCC;
}

@font-face{
src: url(assets/fonts/oswald-v16-latin-regular.ttf);
font-family: oswald;
}

/* ~~ The header is given a width of 100%.
It will extend the full width of the browser.
The rest of the layout will be fixed~~ */
header{
background-color: #004489;
min-width: 1024px;
height: 100px;
clear: both;
}
/*header::after {
content: '';
display: block;
clear: both;
}*/
.navWrapper{
max-width: 1100px;
margin: 0 auto;
}

nav{
float:right;
margin-top: 20px;
padding-right: 50px;
}

nav ul{
list-style: none;
padding: 0;
margin: 0;

}

nav ul li{
display: inline-block;
float: left;
position: relative;

}

nav ul li a{
display: block;
margin: 0;
padding: 10px 10px;
text-decoration: none;
font-family: oswald;
font-size: 25px;
color: #fff;
}


nav ul a:hover, nav ul a:active, nav ul a:focus{
background-color: #065BB0;
}

nav ul ul{
display: none;/**/
position: absolute;
}

/* Display Dropdowns on Hover */
nav ul li:hover > ul {
display:list-item;
}
nav ul ul li{
display: block;
width: 115px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
nav ul ul li a{
color:#242323;
background-color: #8ec6ef;

}
nav ul ul a:hover, nav ul ul a:active, nav ul ul a:focus{
color:#fff;
background-color: #065BB0;
}
<body>
<header>
<div class="navWrapper">
<nav>
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">BGA</a>
<ul>
<li><a href="#">BOOKS</a></li>
<li><a href="#">COURSES</a></li>
</ul>
</li>
<li><a href="#">CONTACT</a></li>
</ul>
</nav>
</div>
</header>
</body>

最佳答案

我不认为这是可能的 CSS,你可以简单地通过使用 jQuery mouseenter 事件来完成:

$('#bga-list').mouseenter(() => {
$('#bga-list > ul').show();
})
@charset "utf-8";
/* CSS Document */
body{
margin: 0;
padding: 0;
background-color: #CCC;
}

@font-face{
src: url(assets/fonts/oswald-v16-latin-regular.ttf);
font-family: oswald;
}

/* ~~ The header is given a width of 100%.
It will extend the full width of the browser.
The rest of the layout will be fixed~~ */
header{
background-color: #004489;
min-width: 1024px;
height: 100px;
clear: both;
}
/*header::after {
content: '';
display: block;
clear: both;
}*/
.navWrapper{
max-width: 1100px;
margin: 0 auto;
}

nav{
float:right;
margin-top: 20px;
padding-right: 50px;
}

nav ul{
list-style: none;
padding: 0;
margin: 0;

}

nav ul li{
display: inline-block;
float: left;
position: relative;

}

nav ul li a{
display: block;
margin: 0;
padding: 10px 10px;
text-decoration: none;
font-family: oswald;
font-size: 25px;
color: #fff;
}


nav ul a:hover, nav ul a:active, nav ul a:focus{
background-color: #065BB0;
}

nav ul ul{
display: none;/**/
position: absolute;
}

/* Display Dropdowns on Hover */

nav ul ul li{
display: block;
width: 115px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
nav ul ul li a{
color:#242323;
background-color: #8ec6ef;

}
nav ul ul a:hover, nav ul ul a:active, nav ul ul a:focus{
color:#fff;
background-color: #065BB0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<header>
<div class="navWrapper">
<nav>
<ul>
<li><a href="#">HOME</a></li>
<li id="bga-list"><a href="#">BGA</a>
<ul>
<li><a href="#">BOOKS</a></li>
<li><a href="#">COURSES</a></li>
</ul>
</li>
<li><a href="#">CONTACT</a></li>
</ul>
</nav>
</div>
</header>
</body>

但是,我认为在 mouseenter 上显示下拉列表并且从不隐藏它不是一个好主意。希望这会有所帮助。

关于html - 导航下拉菜单 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53345960/

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