html - 嵌套列表不会出现在悬停css中
问题描述
我尝试了很多次来处理嵌套列表,但它出现在页面中间而不是在其父级之下。也不会出现使用悬停。我试过了,但没有任何效果。下面是html和css。我应该使用什么保证金和仓位?悬停有什么问题?
<html>
<head>
<title> Life Clinck </title>
<link href="style.css" type="text/css" rel="stylesheet" >
</head>
<body>
<div id="header">
<img height="200px " width="200px" src="logo.jpg">
<h1> Life Clinck
</h1>
<hr>
</div>
<nav class="navClass">
<ul>
<li> <a href="">map </a></li>
<li> <a href=""> apponintment</a></li>
<li> <a href="">contact </a></li>
<li> <a href=""> clincks </a> </li>
<ul class="submenu">
<li> <a href=""> 1</a> </li>
<li> <a href="">2</a></li>
<li> <a href=""> 3 </a></li>
<li><a href=""> 4 </a></li>
<li> <a href="">5 </a></li>
</ul>
</ul>
</nav>
</body>
</html>
这是css代码
body {
background-image: linear-gradient(to top, #c1dfc4 0%, #deecdd 100%);
text-align: center;
}
#header {
background: #FFFFFF;
width: 100%;
height:280px;
margin: 0px auto;
}
h1{
text-align: center;
font-family: "Times new Romans";
font: 28pt;
color:#CC0000;
}
hr
{
color: #dfcaca;
height:10pt;
width: 100%;
}
.navClass > ul{
list-style: none;
}
.navClass > ul > li{
padding: 5px 25px;
display: inline-block;
position: relative;
}
a {
text-decoration: none;
}
ul.submenu{
list-style: none;
margin-left: -10px;
display: none;
}
ul.submenu > li{
font-family: "Tahoma";
}
.navClass li:hover
{
background: #FFFFFF;
left: 0;
}
.navClass li:hover .submenu {
display: block;
}
此致
解决方案
body {
background-image: linear-gradient(to top, #c1dfc4 0%, #deecdd 100%);
text-align: center;
}
#header {
background: #FFFFFF;
width: 100%;
height:280px;
margin: 0px auto;
}
h1{
text-align: center;
font-family: "Times new Romans";
font: 28pt;
color:#CC0000;
}
hr
{
color: #dfcaca;
height:10pt;
width: 100%;
}
.navClass > ul{
list-style: none;
}
.navClass > ul > li{
padding: 5px 25px;
display: inline-block;
position: relative;
}
a {
text-decoration: none;
}
ul.submenu{
list-style: none;
margin-left: -10px;
display: none;
}
ul.submenu > li{
font-family: "Tahoma";
}
.navClass li:hover
{
background: #FFFFFF;
left: 0;
}
.navClass li:hover .submenu {
display: block;
}
<html>
<head>
<title> Life Clinck </title>
<link href="style.css" type="text/css" rel="stylesheet" >
</head>
<body>
<div id="header">
<img height="200px " width="200px" src="logo.jpg">
<h1> Life Clinck
</h1>
<hr>
</div>
<nav class="navClass">
<ul>
<li> <a href="">map </a></li>
<li> <a href=""> apponintment</a></li>
<li> <a href="">contact </a></li>
<li> <a href=""> clincks </a>
<ul class="submenu"> /*---> Moved this ul inside upper li, and done...*/
<li> <a href=""> 1</a> </li>
<li> <a href="">2</a></li>
<li> <a href=""> 3 </a></li>
<li><a href=""> 4 </a></li>
<li> <a href="">5 </a></li>
</ul>
</li>
</ul>
</nav>
</body>
</html>
移动 li 内的嵌套 ul 以使其工作。见片段......见下面的变化......
<li> <a href=""> apponintment</a></li>
<li> <a href="">contact </a></li>
<li> <a href=""> clincks </a>
<ul class="submenu"> /*---> Moved this ul inside upper li, and done...*/
<li> <a href=""> 1</a> </li>
<li> <a href="">2</a></li>
<li> <a href=""> 3 </a></li>
<li><a href=""> 4 </a></li>
<li> <a href="">5 </a></li>
</ul>
</li>
推荐阅读
- javascript - 使用 react js 从 json 文件中提取数据
- android - FirebaseFirestore.getInstance() 和应用程序已停止
- sql - SQL 根据特定列和日期汇总小计
- c - 将联合作为宏中的两个参数之一传递
- python - 微软图形 API Python
- laravel-nova - 如何创建返回父列表的链接?
- javascript - 编写多个隐藏显示 jquery 函数的更简洁的方法?
- ruby-on-rails - Github 页面上的图像显示错误 - 使用 Jekyll
- android - 能够在 Windows 10 上使用 USB 调试/文件传输查看 Android 手机的根文件
- ubuntu - 为什么我不能使用创建的 phpmyadmin 用户在 phpmyadmin 中添加新数据库?