我不能让我的垂直菜单水平移动。请帮助,因为我试图左右浮动ul并尝试内联无。我不太确定我对哪个类应该放入内联或浮动而感到困惑。提前感谢大家对此的帮助,因为这个一直在疯狂,我确信这是一个简单的解决方案,但我无法看到它。
/* define a fixed width for the entire menu */
.horiz_nav {
width: 100px;
float: right;
}
/* reset our lists to remove bullet points and padding */
.mainmenu_horiz {
list-style: none;
padding: 0;
margin: 0;
}
.mainmenu_horiz ul {
list-style: none;
padding: 0;
margin: 0;
}
.menu_horiz li {
list-style: none;
padding: 0;
margin: 0;
display: inline-block;
float: right;
}
/* make ALL links (main and submenu) have padding and background color */
.mainmenu_horiz a {
display: block;
background-color: #8EC752;
text-decoration: none;
padding: 10px;
color: #000;
}
/* add hover behaviour */
.mainmenu_horiz a:hover {
background-color: #ABD281;
}
/* when hovering over a .mainmenu item,
display the submenu inside it.
we're changing the submenu's max-height from 0 to 200px;
*/
.mainmenu_horiz li:hover .submenu_horiz {
display: block;
max-height: 200px;
}
/*
we now overwrite the background-color for .submenu links only.
CSS reads down the page, so code at the bottom will overwrite the code at the top.
*/
.submenu_horiz a {
background-color: #999;
}
/* hover behaviour for links inside .submenu */
.submenu_horiz a:hover {
background-color: #666;
}
/* this is the initial state of all submenus.
we set it to max-height: 0, and hide the overflowed content.
*/
.submenu_horiz {
overflow: hidden;
max-height: 0;
-webkit-transition: all 0.5s ease-out;
}
<header class="header" id="header">
<div id="horiz_nav" class="horiz_nav">
<ul class="mainmenu_horiz">
<li><a href="">Home</a></li>
<li><a href="">Courses</a>
<ul class="submenu_horiz">
<li><a href="">Motor Learning</a></li>
<li><a href="">MS II</a></li>
</ul>
</li>
</ul>
</div>
</header>
答案 0 :(得分:0)
首先,.menu_horiz li
应该是.mainmenu_horiz li
,然后这应该是float: left
,不对,加上它不需要浮动*和* display: inline-block
- 其中一个就足够了。
.mainmenu_horiz li{
list-style: none;
padding: 0;
margin: 0;
float: left;
}
答案 1 :(得分:0)
/ *我刚把你的css改成了这个。只需检查它是否适合您。 * /
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}