简体   繁体   English

CSS-有人可以帮助我找出下拉菜单导航出现的问题吗?

[英]CSS - Can someone help me figure out where I went wrong with my dropdown menu nav?

I wanted to learn how to create a dropdown nav bar in the simplest and cleanest way possible. 我想学习如何以最简单,最简洁的方式创建下拉导航栏。 I followed this wiki how CSS-only dropdown menu guide, but it seems my code is not compatible with the suggested additions. 我按照这个wiki的 CSS-only下拉菜单指南进行操作,但是看来我的代码与建议的添加内容不兼容。

Could someone tell me where the conflicts within the code occur, or if there is a simpler way to implement a dropdown menu (familiar with jQuery/JavaScript if that's easier)? 有人可以告诉我代码中的冲突发生在哪里,或者是否有一种更简单的方法来实现下拉菜单(如果更简单,请熟悉jQuery / JavaScript)?

HTML: HTML:

<!DOCTYPE html>

<html>

<head>

    <link type="text/css" rel="stylesheet" href="template_ss.css"/>

    <title></title>


    </div>
</head>

<body>

<!--------------------------header--------------------------->
    <div id="headerDiv">
        <div id="titleDiv">
            <p id= "titleText"><span>Your</span>Uni<span>verse</span></p>
        </div>

        <div class="navDiv">    
            <ul class="navUL">
                <li><a href="#!">Home</a></li>  
                <li>
                    <a href="#!">Universe</a>
                    <ul class="dropdown">
                        <li><a href="#!">1</a></li>
                        <li><a href="#!">2</a></li>
                        <li><a href="#!">3</a></li> 
                    </ul>
                </li>
                <li>
                    <p><a href="#!">Browse</a></p>
                    <ul class="dropdown">
                        <li><a href="#!">Planets</a></li>
                        <li><a href="#!">Galaxies</a></li>
                        <li><a href="#!">Odities</a></li>
                    </ul>   
                </li>
                <li>
                    <p><a href="#!">Random</a></p>
                    <ul class="dropdown">
                        <li><a href="#!">Quantum</a></li>
                        <li><a href="#!">Solar</a></li>
                        <li><a href="#!">Projectile</a></li>
                    </ul>   
                </li>
                <li>
                    <p><a href="#!">Profile</a></p>
                    <ul class="dropdown">
                        <li><a href="#!">My profile</a></li>
                        <li><a href="#!">Edit profile</a></li>
                    </ul>
                </li>
                <li>
                    <p><a href="#!">How it works</a></p>
                </li>
            </ul>
        </div>
        <div class="searchDiv">
            <form>
                <input type="text" placeholder="explore..." required>
                <input type="button" value="Search">
            </form>
        </div>
<!---------------------------body--------------------------->
    <div class="bodyDiv"></div>
</body>
</html>

CSS: CSS:

/*-------------------header----------------------*/
body{
margin:0px;
}
#headerDiv{
position: fixed;
height:12%;
width:100%;
background-image:url("deepspace.png");
background-repeat:repeat-x;
text-align: center;
}
#titleDiv{ 
width: auto;
margin: auto 0;
}
#titleText{
color:white;
font-size:130%;
text-allign:center;
font-family:verdana,san serif;
}
span:first-child{    
color:blue;
}
span{
color:purple;
}
.navDiv{
display:inline-block;
}
.navUL{
position:relative;
display:inline-block;
list-style-type:none;
margin: auto 0;
padding:0;
border-top:1 solid;
border-right:1 solid;
border-left:1 solid;
width:100%;
}
.navUL:after{
content:"";
display:table;
}
.navUL li{
padding: .2em 2em;
margin:2em,2em,2em,2em;
color: #fff;
background-color: #036;
display:inline-block;
text-align:center;
}
.dropdown{
position:absolute;
display:none;
background-color:white;
}
.navUL ul li:hover > ul{
display:inline;
}
.navUL>ul>li:after{
content:"\25BC";
font-size:.5em;
display:inline;
position:relative;
}
.searchDiv{
display:inline-block;
}
/*------------------body--------------------*/
.bodyDiv{
text-align:center;
float:left;
background-color:grey;
height:80%;
width:70%;
position:relative;
top:80%;
left:50%;
-ms-transform: translate(-50%, -50%);
-webkit-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
}

The li at level 1 should has property position:relative , so that the child ul will be able to set the position according to its parent. 级别1的li应该具有position:relative属性,以便子ul能够根据其父项设置位置。 I make some changes, see the fiddle: click here 我进行了一些更改,请参见小提琴: 单击此处

暂无
暂无

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

相关问题 CSS-需要帮助找出下拉菜单导航出错的地方 - CSS - Need help figuring out where I went wrong with my dropdown menu nav 我的导航栏下拉菜单位于幻灯片后面。 有人可以帮我弄清楚吗? - My dropdown from nav bar goes behind the slideshow. Could someone help me figure it out? 有人可以告诉我哪里出错了吗? - Can someone please tell me where I went wrong? 有人可以帮我弄清楚我的代码有什么问题吗? 它将 RNA 序列翻译成蛋白质 - Can someone help me figure out what's wrong with my code?. It translates RNA sequences into proteins 我似乎无法弄清楚如何修复JavaScript中的两个棉绒。 有人可以帮我理解吗? - I can't seem to figure out how to fix two lints in my javascript. Can someone help me understand? 有人可以解释我的粘性导航菜单出了什么问题吗? - Can someone explain what went wrong with my sticky navigation menu? 下拉按钮在引导程序中无法正常工作。 有人可以告诉我我哪里出了问题 - Dropdown button not working properly in bootstrap. Can some body tell me where i went wrong 有人可以告诉我我的下拉菜单javascript代码有什么问题吗 - Can someone tell me what's wrong with my dropdown menu javascript code 播放阵列中随机选择的音频,无法弄清楚我哪里出了错 - playing a randomly selected piece of audio from an array, cant figure out where I went wrong 在进行计算时,如何获得某个值以对应另一个值? 以前有过,现在不知道哪里出错了 - How can I get a certain value to correspond to another when doing a calculation? I had it previously, now I can't figure out where I went wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM