简体   繁体   English

如何使下拉菜单垂直

[英]How to make the dropdown menu vertical

I have a horizontal menu at the top of the page and I want a vertical drop down menu to appear below one of the horizontal menu items. 我在页面顶部有一个水平菜单,并且希望垂直下拉菜单出现在一个水平菜单项的下方。 The menus are not connected ... the code that generates the horizontal menu at the top of the page is completely separate from the code for the vertical menu I want to appear below. 菜单未连接...在页面顶部生成水平菜单的代码与我要在下面显示的垂直菜单的代码完全分开。

But, the menu is appearing horizontal. 但是,菜单显示为水平。 What do I have to do to make each menu item appear vertically. 我要怎么做才能使每个菜单项垂直显示。

I have a fiddle at js fiddle 我在JS小提琴中有小提琴

Here is a bit of the code as I have to paste something here .. 这是一些代码,因为我必须在此处粘贴一些内容。

#dvMenu ul 
{
padding:0;
margin:0;
list-style: none;
position: relative;
}

If you look at the fiddle, run it and click on 'Link Two' - the sub-menu appears - but it is horizontal. 如果您查看小提琴,请运行它并单击“链接二”-出现子菜单-但它是水平的。 What do I have to do to get it to appear vertically? 我要怎么做才能使其垂直出现?

Remove the float: left from #dvMenu li . 删除float: left #dvMenu li float: left

Check your updated Fiddle . 检查您更新的小提琴

If you add the clear property to your stylesheet, then the floating elements won't be able to float side by side anymore. 如果将clear属性添加到样式表中,则浮动元素将不再能够并排浮动。

http://www.w3schools.com/cssref/pr_class_clear.asp http://www.w3schools.com/cssref/pr_class_clear.asp

updated fiddle 更新的小提琴

#dvMenu ul li 
{
  float: left;
  clear:both;
  display: block;
  width: 140px;
  text-align: center;
  line-height: 21px;
}

http://jsfiddle.net/mc7kLc8c/2/ http://jsfiddle.net/mc7kLc8c/2/

更改position:从CSS中的relative position:更改为absolute position:

remove display: inline; 删除display: inline; from #navcontainer ul li 来自#navcontainer ul li

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM