HTML/CSS 在侧边菜单右侧添加下拉菜单

标签 html css

我尝试将下拉选项添加到我当前的固定侧边栏菜单中。

当我尝试添加新列表以添加额外菜单时,它只是在下方显示它们。当我将鼠标悬停在 Three 上时,我希望 Three One 显示在下方 ThreeThree Two 的右侧三一

当我将鼠标悬停在 Four 上时,我希望 Four One"显示在 FourFour Two< 的右侧Four One 下方。当我将鼠标悬停在 Four One One

上时,也会发生同样的情况

下面是我的 HTMl 和 CSS

body {
    font: 15px/1.5 Arial, Helvetica, sans-serif;
    padding: 0;
    margin: 0;
    background-color: #2E2E2E;
}

header {
    background: #424242;
    color: #ffffff;
    border-right: #FA5858 3px solid;
    position: fixed;
    top: 0;
    bottom: 0;
    width: 175px;
}

header ul {
    padding: 0;
}

header a {
    color: #ffffff;
    text-decoration: none;
    font-size: 16px;
}

header li {
    ;
    display: block;
}

span {
    margin-right: 15px;
}

header ul li {
    padding: 15px;
}

header ul li:hover {
    background-color: #FA5858;
}
<!DOCTYPE html>
<html>
<head>
	<title>Menu</title>
	<link rel="stylesheet" type="text/css" href="test.css">
	<link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet">
</head>
<body>
	<header>
		<div class="container">
			<center>
				<h1>Logo Here</h1>
			</center>
			<ul>
				<li>
					<a href=""><span class="far fa-newspaper"></span>One</a>
				</li>
				<li>
					<a href=""><span class="far fa-list-alt"></span>Two</a>
				</li>
				<li>
					<a href=""><span class="fas fa-user-secret"></span>Three</a>
				</li>
				<ul>
					<li>
					<a href=""><span class="fas fa-user-secret"></span>Three One</a>
					</li>
					<li>
					<a href=""><span class="fas fa-user-secret"></span>Three Two</a>
					</li>
				</ul>
				<li>
					<a href=""><span class="fas fa-shopping-basket"></span>Four</a>
				</li>
				<ul>
					<li>
					<a href=""><span class="fas fa-user-secret"></span>Four One</a>
					</li>
					<ul>
						<li>
						<a href=""><span class="fas fa-user-secret"></span>Four One One</a>
						</li>
						<li>
						<a href=""><span class="fas fa-user-secret"></span>Four One Two</a>
						</li>
					</ul>
					<li>
					<a href=""><span class="fas fa-user-secret"></span>Four Two</a>
					</li>
				</ul>
				<li>
					<a href=""><span class="far fa-question-circle"></span>Five</a>
				</li>
			</ul>
		</div>
	</header>
</body>
</html>

最佳答案

试试这个,你的脸上就会露出笑容:)

html

<header>
 <div class="container">
<center>
  <h1>Logo Here</h1>
</center>
<ul>
  <li> <a href=""><span class="far fa-newspaper"></span>One</a> </li>
  <li> <a href=""><span class="far fa-list-alt"></span>Two</a> </li>
  <li> <a href=""><span class="fas fa-user-secret"></span>Three</a> 
    <ul>
    <li> <a href=""><span class="fas fa-user-secret"></span>Three One</a> 
        <ul>
            <li> <a href=""><span class="fas fa-user-secret"></span>Three One One</a> </li>
            <li> <a href=""><span class="fas fa-user-secret"></span>Three One Two</a> </li>
         </ul>
     </li>
    <li> <a href=""><span class="fas fa-user-secret"></span>Three Two</a> </li>
  </ul>
  </li>
   </ul>
   </div>
 </header>

并改进CSS

body {
font: 15px/1.5 Arial, Helvetica, sans-serif;
padding: 0;
margin: 0;
background-color: #2E2E2E;
}

header {
background: #424242;
color: #ffffff;
border-right: #FA5858 3px solid;
position: fixed;
top: 0;
bottom: 0;
width: 175px;
}

header ul {padding: 0;}

header a {
color: #ffffff;
text-decoration: none;
font-size: 16px;
    }

    header li {
display: block;
position:relative;
 }

span {
margin-right: 15px;
  }

    header ul li {
padding: 15px;
     }

  header ul li:hover {
background-color: #FA5858;
 }
  header ul li ul{display:none;}
    header ul li:hover ul{display:block; position:absolute; top:0; left:170px; background:#fff; width:200px;}
      header ul li ul li a{color:#000; display:inline-block; width:100%;}
     header ul li ul li{display:inline-block; width:100%; padding:0;}
    header ul li ul li ul{display:none !important;}
  header ul li ul li:hover ul{display:block !important;}

jsfiddle

关于HTML/CSS 在侧边菜单右侧添加下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48839807/

相关文章:

javascript - 第一次加载 HTML 页面时 JS 不运行

javascript - node.js 和 jquery web 的 UI

javascript - 添加填充弄乱了进度条

html - 如何在 Internet Explorer 的 XSL 文档中包含 CSS 样式表?

javascript - 将除内部 div 之前的表之外的所有表隐藏在 div 中

Android 显示超长滚动网页——这是不正确的行为

javascript - 我怎样才能让这个下拉列表总是显示在父 div 之外?

JavaScript 位置/方向计算

javascript - 扫描特定 html 元素的页面并分配 css 类

css - 如何更改 c3.js 图表中文本的颜色?