我有一个主菜单栏,它有一个下拉菜单,该菜单有一个子菜单。如何让子下拉菜单显示在第一个下拉菜单中“下拉2”链接的左侧?我还想将子菜单的顶部对齐到“下拉2”链接的顶部。现在它出现在链接的下方和左侧。
HTML:
<img src="#" width="100%" height="100px">
<div class="TopMenuBar">
<ul>
<li><a href="#">Side</a></li>
<li class="dropdown"><a href="#">menu</a>
<div class="dropdown-menu">
<ul>
<li><a href="#">drop down 1</a></li>
<li class="sub-dropdown"><a href="#">drop down 2</a>
<div class="sub-dropdown-menu">
<ul>
<li><a href="#">sub drop down 1</a></li>
<li><a href="#">sub drop down 2</a></li>
</ul>
</div>
</li>
<li><a href="#">drop down 3</a></li>
</ul>
</div>
</li><a href="#">Bar</a></li>
</ul>
</div>
<div class="SideMenuBar">
<ul>
<li><a href="#">Side</a></li>
<li><a href="#">Menu</a></li>
<li><a href="#">Bar</a></li>
</ul>
</div>
<h1>h1 Header</h1>
<main>
<h2>h2 Header</h2>
<p>Main paragraph</p>
<a href="#">Main link</a>
<ul>
<li>Main list item</li>
<li>Main list item</li>
<li>Main list item</li>
</ul>
<h2>h2 Header</h2>
<p>Main paragraph</p>
<a href="#">Main link</a>
<ul>
<li>Main list item</li>
<li>Main list item</li>
<li>Main list item</li>
</ul>
</main>
CSS:
.TopMenuBar {
border: none;
background-color: purple;
width: 100%;
margin: 0;
padding: 0;
}
.TopMenuBar>ul {
display: flex;
justify-content: space-between;
margin: 0;
padding: 0;
}
.TopMenuBar>ul, .dropdown-menu>ul, .sub-dropdown-menu>ul{
list-style-type: none;
margin: 0;
padding: 0;
}
.TopMenuBar>li {
display: inline;
}
.TopMenuBar a, .dropdown-menu a, .sub-dropdown-menu a{
color: white;
text-decoration: none;
padding: 20px;
display: block
}
/* Applys to all links under class TopMenuBar on hover */
.TopMenuBar a:hover {
background-color: #b14eb1;
color: black;
}
.dropdown-menu {
}
.dropdown-menu, .sub-dropdown-menu{
display: none;
background-color: purple;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
position: absolute;
z-index: 1;
}
/* Applys to all links under class TopMenuBar */
.dropdown-menu a {
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown:hover .dropdown-menu{
display: block;
}
.sub-dropdown:hover .sub-dropdown-menu{
display: table;
}
.SideMenuBar {
background-color: orange;
margin-left: 20px;
margin-top: 0;
display: flex;
height: 100vh;
float: left;
}
.SideMenuBar ul {
padding: 0;
margin: 0;
list-style-type: none;
justify-content: space-between;
display: flex;
flex-direction: column;
}
.SideMenuBar li a {
color: white;
text-decoration: none;
padding: 20px;
display: list-item;
}
.SideMenuBar li a:hover {
background-color: #fcbf7e;
color: black;
}
main {
padding-left: 10px;
display: table
}
h1 {
text-align: center;
}
这是codepen
的工作模型答案 0 :(得分:4)
将其添加到样式表的底部。
library(ggplot2)
ggplot() +
geom_line(aes(x=1:length(Nts), y=Nts, col='Nts')) +
geom_line(aes(x=1:length(n450), y=n450, col='n450')) +
geom_line(aes(x=1:length(n05), y=n05, col='n05')) +
xlab('x')+
ylab('y')+
theme_bw()
答案 1 :(得分:0)
请参阅此代码示例,它可能会对您有所帮助
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<style type="text/css">
.dropdown-submenu {
position: relative;
}
.dropdown-submenu>.dropdown-menu {
top: 0;
left: 100%;
margin-top: -6px;
margin-left: -1px;
-webkit-border-radius: 0 6px 6px 6px;
-moz-border-radius: 0 6px 6px;
border-radius: 0 6px 6px 6px;
}
.dropdown-submenu:hover>.dropdown-menu {
display: block;
}
.dropdown-submenu>a:after {
display: block;
content: " ";
float: right;
width: 0;
height: 0;
border-color: transparent;
border-style: solid;
border-width: 5px 0 5px 5px;
border-left-color: #ccc;
margin-top: 5px;
margin-right: -10px;
}
.dropdown-submenu:hover>a:after {
border-left-color: #fff;
}
.dropdown-submenu.pull-left {
float: none;
}
.dropdown-submenu.pull-left>.dropdown-menu {
left: -100%;
margin-left: 10px;
-webkit-border-radius: 6px 0 6px 6px;
-moz-border-radius: 6px 0 6px 6px;
border-radius: 6px 0 6px 6px;
}
</style>
</head>
<body>
<div class="container">
<br>
<div class="row">
<div class="dropdown">
<a id="dLabel" role="button" data-toggle="dropdown" class="btn btn-primary" data-target="#" href="/page.html">
Dropdown <span class="caret"></span>
</a>
<ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
<li><a href="#">Some action</a></li>
<li><a href="#">Some other action</a></li>
<li class="divider"></li>
<li class="dropdown-submenu">
<a tabindex="-1" href="#">Hover me for more options</a>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Second level</a></li>
<li class="dropdown-submenu">
<a href="#">Even More..</a>
<ul class="dropdown-menu">
<li><a href="#">3rd level</a></li>
<li><a href="#">3rd level</a></li>
</ul>
</li>
<li><a href="#">Second level</a></li>
<li><a href="#">Second level</a></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</body>
</html>