简体   繁体   English

将下拉子菜单添加到代码中

[英]Adding drop down sub menu to code

I have been trying to add a drop down menu to this code but always seem to get turned around. 我一直在尝试为这段代码添加一个下拉菜单,但似乎总是转过身来。 I just want a basic look to the subnav with a simple rollover effect. 我只想通过简单的翻转效果对subnav进行基本的查看。 Every time i try different code it uses home image in the drop down menu and will not disappear when it is not hovered over. 每次我尝试不同的代码时,它会在下拉菜单中使用主页图像,并且当它没有悬停时不会消失。 Ideas? 想法?

HTML: HTML:

   <ul class="navbar">
      <li class="navbar1"><a href="home.html" title="Home">Home</a>
      <ul class="subnav"> 
               <li><a href="#">Menu 1 </a></li>
               <li><a href="#">Menu 2 </a></li>
           </ul>
         </li>

    </ul> 

CSS: CSS:

ul.navbar {
width:1000px;
list-style:none;
height:40px;
}
ul.navbar li {
display:inline;
}
ul.navbar li a {
height:40px;
float:left;
text-indent:-9999px;
}
/* Home 0 */
ul.navbar li.navbar1 a {
width:86px;
background:url(../pelican%20outfitters/navbar2.fw.png)
 no-repeat 0 0; 
}
ul.navbar  li.navbar1 a:hover {
background-position:0 -40px; 
}
ul.navbar  li.navbar1 a.current {
background-position:0 -80px; 
}

You should delete the text-indent:-9999px and add this to your css 你应该删除text-indent:-9999px并将其添加到你的css中

Delete row: 删除行:

ul.navbar li a { text-indent:-9999px }

Css: CSS:

.navbar li ul {display:none;}
.navbar li:hover ul {display:block;}

Than you have a basic navbar with hidden subnavs. 比你有一个隐藏的subnavs基本导航栏。
From here you can try it with your image. 从这里你可以尝试与你的形象。

The demo is your code with the new code.. 该演示是您的代码与新代码..

DEMO DEMO

More like you want is, dont delete the css.. but only add those 2 lines and this 1: 更像你想要的是,不要删除CSS ..但只添加这两行,这1:

.navbar li:hover li a{ text-indent:1px; background:white; }

DEMO 2 (without your img (don't know what it is)). DEMO 2 (没有你的img(不知道它是什么))。

Latest update after the fiddle comment: 小提琴评论后的最新更新:
You should specify your html and css.. a just added a class to the first link class="home" and to accomodations class="accomodations" 你应该指定你的html和css ..只是在第一个链接class="home"和住宿class="accomodations"添加了一个类

And changed it in the css.. 并在css中改变了它..

/* Home */
ul.navbar li.navbar1 a.home {
   width:86px;
   background:url(http://s12.postimg.org/rszejjscd/navbar2_fw.png)
   no-repeat 0 0; 
}
/* Accomodations */
   ul.navbar li.navbar2 a.accomodations {
   width:220px;
   background: url(http://s12.postimg.org/rszejjscd/navbar2_fw.png) no-repeat -86px 0;
}

DEMO 3 演示3

HTML HTML

   <nav>
        <ul class="navbar">
            <li class="navbar1"><a href="home.html" title="Home">Home</a>

                <ul class="subnav">
                    <li><a href="#">Menu 1 </a>

                    </li>
                    <li><a href="#">Menu 2 </a>

                    </li>
                </ul>
            </li>
        </ul>
    </nav>

CSS CSS

nav {
    margin: 20px auto;

}
nav ul ul {
    display: none;
}
nav ul li:hover > ul {
    display: block;
}
nav ul li
{
    width:100px;
}

ul li ul li
{  width:200px;

}
nav ul {
    font-size: 25px;
    background: white;
    padding: 0px;
    border-radius: 10px;
    border-style: solid;
    list-style: none;
    position: relative;
    display: inline-table;
}
nav ul:after {
    content:"";
    clear: both;
    display: block;
}
nav ul li {
    float: left;
}
nav ul li:hover {
    background: black;
    position:relative;
    z-index:1;
}
nav ul li:hover a {
    color: white;
    position:relative;
    z-index:1;
}
nav ul li a {
    display: block;
    padding: 15px 20px;
    color: black;
    text-decoration: none;
}
nav ul ul {
    background: #000000;
    border-radius: 0px 0px 10px 10px;
    padding: 0;
    position: absolute;
    top: 100%;
}
nav ul ul li {
    float: none;
}
nav ul ul li a {
    padding: 15px 20px;
}
nav ul ul li a:hover {
    background: #2E2E2E;
    border-radius: 10px;
}

Output: 输出:

在此输入图像描述

Working Fiddle 工作小提琴

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

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