【发布时间】:2016-01-07 05:00:31
【问题描述】:
我想创建一个像这个网站http://www.jamieoliver.com/ 这样的下拉菜单。 要查看下拉菜单,只需将导航栏悬停在此 http://www.jamieoliver.com/ 网站上
【问题讨论】:
-
请在询问之前自己尝试一下。显示一些你尝试过的代码,然后一些可以帮助你
标签: javascript jquery html css angularjs
我想创建一个像这个网站http://www.jamieoliver.com/ 这样的下拉菜单。 要查看下拉菜单,只需将导航栏悬停在此 http://www.jamieoliver.com/ 网站上
【问题讨论】:
标签: javascript jquery html css angularjs
你应该看到这个问题:
How to make twitter bootstrap menu dropdown on hover rather than click,
无论如何,您应该提供一些代码或一些您在询问之前做过的尝试,就像@Chris Beckett 所说的那样。
【讨论】:
这里有一个简单的示例供您查看。将来,请在此处提问之前尝试自己尝试执行此操作。这样一来,在有人用勺子递给你之前,你至少已经尝试过了。
HTML:
<body class="news">
<header>
<div class="nav">
<ul>
<li class="home"><a href="#">Home</a></li>
<li class="tutorials"><a href="#">Tutorials</a>
<ul>
<li><a href="#">Tutorial</a></li>
<li><a href="#">Tutorial2</a></li>
<li><a href="#">Tutorial3</a></li>
</ul>
</li>
<li class="about"><a class="active" href="#">About</a></li>
<li class="news"><a href="#">Newsletter</a>
<ul>
<li><a href="#">News1</a></li>
<li><a href="#">News2</a></li>
<li><a href="#">News3</a></li>
</ul>
</li>
<li class="contact"><a href="#">Contact</a></li>
</ul>
</div>
</header>
</body>
CSS:
body {
margin: 0;
padding: 0;
background: #ccc;
}
.nav ul {
list-style: none;
background-color: #444;
text-align: center;
padding: 0;
margin: 0;
}
.nav li {
font-family: 'Oswald', sans-serif;
font-size: 1.2em;
line-height: 40px;
text-align: left;
}
.nav a {
text-decoration: none;
color: #fff;
display: block;
padding-left: 15px;
border-bottom: 1px solid #888;
transition: .3s background-color;
}
.nav a:hover {
background-color: #005f5f;
}
.nav a.active {
background-color: #aaa;
color: #444;
cursor: default;
}
/* Sub Menus */
.nav li li {
font-size: .8em;
}
/*******************************************
Style menu for larger screens
Using 650px (130px each * 5 items), but ems
or other values could be used depending on other factors
********************************************/
@media screen and (min-width: 650px) {
.nav li {
width: 130px;
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 1.4em;
display: inline-block;
margin-right: -4px;
}
.nav a {
border-bottom: none;
}
.nav > ul > li {
text-align: center;
}
.nav > ul > li > a {
padding-left: 0;
}
/* Sub Menus */
.nav li ul {
position: absolute;
display: none;
left: 0;
width: 100%;
height: 400px;
background-color: grey;
}
.nav li:hover ul {
display: block;
}
.nav li ul li {
float: left;
width: 20%;
}
}
【讨论】: