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

itry2c0de

我试图向我当前的固定侧边栏菜单添加下拉选项。

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

当我将鼠标悬停在上方时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;
}

标头 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;}

提琴手

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章