[英]Vertical Menu Issues Using CSS & HTML
I am trying to display a vertical menu in a defined column on the right using a statement with a specific class "vmenu". 我正在尝试使用带有特定类“ vmenu”的语句在右侧的定义列中显示垂直菜单。 Everything seems to work, and I get the menu items on screen but they are not stacked one on top of the other like this:
一切似乎都正常,并且屏幕上显示了菜单项,但它们没有像这样堆叠在一起:
Menu 1
Menu 2
Menu 3
Menu 4
instead they are shown like they are in two columns: 而是将它们显示为两列:
Menu 1 | Menu 2
Menu 3 | Menu 4
The CSS file also has a horizontal menu defined and I'm not sure if that is interfering with the results (the horizontal & drop down menus are working just great). CSS文件还定义了一个水平菜单,我不确定这是否会干扰结果(水平和下拉菜单的效果很好)。 Any help would be greatly appreciated.
任何帮助将不胜感激。
I have tried to add a [class="vmenu"] to both the [ul] and each [li] statement without any change in the results. 我试图将[class =“ vmenu”]添加到[ul]和每个[li]语句中,而结果没有任何变化。
The CSS Code For Vertical Menus: 垂直菜单的CSS代码:
.vmenu ul {
list-style-type: none;
margin: 0;
padding: 0;
width: 200px;
background-color: #f1f1f1;
border: 1px solid #555;
}
.vmenu li a {
display: block;
color: #000;
padding: 8px 16px;
text-decoration: none;
}
.vmenu li {
text-align: center;
border-bottom: 1px solid #555;
}
.vmenu li:last-child {
border-bottom: none;
}
.vmenu li a.active {
background-color: #4CAF50;
color: white;
}
.vmenu li a:hover:not(.active) {
background-color: #555;
color: white;
}
The CSS Code for Horiz. Horiz的CSS代码。 Menus:
菜单:
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1;}
.dropdown:hover .dropdown-content {
display: block;
}
.active {
background-color: #4CAF50;
}
The HTML Code: HTML代码:
<div class="column2right">
<p> The Right Side</p><br>
<div class="vmenu">
<ul>
<li><a href="#">Menu 1</a></li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
<li><a href="#">Menu 4</a></li>
</ul>
</div>
</div>
Your problem lies in horiz.css
which is affecting all ul, li, a
elements. 您的问题出在
horiz.css
,这影响了所有ul, li, a
元素。 Make it look as you did for .vmenu
like this: 使它看起来像您对
.vmenu
所做的那样,如下所示:
.hmenu ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
.hmenu li {
float: left;
}
.hmenu li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.hmenu li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.hmenu li.dropdown {
display: inline-block;
}
.hmenu .dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.hmenu .dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.hmenu .dropdown-content a:hover {background-color: #f1f1f1;}
.hmenu .dropdown:hover .dropdown-content {
display: block;
}
.hmenu .active {
background-color: #4CAF50;
}
Hope the issue is with the float property being applied through horizontal menu. 希望问题出在通过水平菜单应用float属性。 Easy fix can be to remove the float for vmenu as
简单的解决方法是删除vmenu的浮动
.vmenu li {
text-align: center;
border-bottom: 1px solid #555;
float:none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.