我的html / css代码干扰了我的 HTML / CSS 下拉菜单
我的导航栏上方有一个文本框,但css代码与我的css下拉列表相互关联。
HTML
<title>Mingamez.com</title>
<link rel="shortcut icon" href="images/favicon.png">
<link rel="stylesheet" type="text/css" href="css/main.css"/>
</head>
<div id='cssmenu'>
<ul>
<li class='active'><a href='index.html'><span><img style="height: 35px;width:75;" src="images/logo_image.png" alt="website logo"/></span></a></li>
<li class='has-sub'><a href='#'><span><img src="images/menu_image.png" alt="Menu"/> </span></a>
<ul>
<li class='has-sub'><a href='#'><span>Product 1</span></a>
<ul>
<li><a href='#'><span>Sub Item</span></a></li>
<li class='last'><a href='#'><span>Sub Item</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Product 2</span></a>
<ul>
<li><a href='#'><span>Sub Item</span></a></li>
<li class='last'><a href='#'><span>Sub Item</span></a></li>
</ul>
</li>
</ul>
</div>
<form method="get" action="search" id="advsearch">
<input name="q" type="text" size="40" placeholder="Search..." />
</form>
</html>
CSS
/** Body */
body{
background-color:#9FBAC4;
}
/** Advanced css menu */
#cssmenu ul { margin: 0; padding: 0; z-index:-1;}
#cssmenu li { margin: 0; padding: 0; z-index:-1;}
#cssmenu a { margin: 0; padding: 0; z-index:-1;}
#cssmenu ul {list-style: none; z-index:-1;}
#cssmenu a {text-decoration: none; z-index:-1;}
#cssmenu { height: 62px; background-color: rgb(35,35,35); box-shadow: 0px 2px 3px rgba(0,0,0,.4);}
#cssmenu { position: fixed; left: 0; top: 0; width: 100%; z-index:-1;}
#cssmenu > ul > li {
float: left;
margin-right: 35px;
margin-left: 35px;
position: relative;
}
#cssmenu > ul > li > a {
color: rgb(160,160,160);
font-family: Verdana, 'Lucida Grande';
font-size: 15px;
line-height: 70px;
padding: 15px 20px;
-webkit-transition: color .15s;
-moz-transition: color .15s;
-o-transition: color .15s;
transition: color .15s;
}
#cssmenu > ul > li > a:hover {color: rgb(250,250,250); }
#cssmenu > ul > li > ul {
opacity: 0;
visibility: hidden;
padding: 16px 0 20px 0;
background-color: rgb(250,250,250);
text-align: left;
position: absolute;
top: 55px;
left: 50%;
margin-left: -90px;
width: 180px;
-webkit-transition: all .3s .1s;
-moz-transition: all .3s .1s;
-o-transition: all .3s .1s;
transition: all .3s .1s;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0px 1px 3px rgba(0,0,0,.4);
-moz-box-shadow: 0px 1px 3px rgba(0,0,0,.4);
box-shadow: 0px 1px 3px rgba(0,0,0,.4);
}
#cssmenu > ul > li:hover > ul {
opacity: 1;
top: 68px;
visibility: visible;
}
#cssmenu > ul > li > ul:before{
content: '';
display: block;
border-color: transparent transparent rgb(250,250,250) transparent;
border-style: solid;
border-width: 10px;
position: absolute;
top: -20px;
left: 50%;
margin-left: -10px;
}
#cssmenu > ul ul > li { position: relative;}
#cssmenu ul ul a{
color: rgb(50,50,50);
font-family: Verdana, 'Lucida Grande';
font-size: 13px;
background-color: rgb(250,250,250);
padding: 5px 8px 7px 16px;
display: block;
-webkit-transition: background-color .1s;
-moz-transition: background-color .1s;
-o-transition: background-color .1s;
transition: background-color .1s;
}
#cssmenu ul ul a:hover {background-color: rgb(240,240,240);}
#cssmenu ul ul ul {
visibility: hidden;
opacity: 0;
position: absolute;
top: -14px;
right: 206px;
padding: 16px 0 20px 0;
background-color: rgb(250,250,250);
text-align: left;
width: 160px;
-webkit-transition: all .83s;
-moz-transition: all .83s;
-o-transition: all .83s;
transition: all .83s;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0px 1px 3px rgba(0,0,0,.4);
-moz-box-shadow: 0px 1px 3px rgba(0,0,0,.4);
box-shadow: 0px 1px 3px rgba(0,0,0,.4);
}
#cssmenu ul ul > li:hover > ul { opacity: 1; left: -170px; visibility: visible;}
#cssmenu ul ul a:hover{
background-color: rgb(0,133,143);
color: rgb(240,240,240);
}
/** Advanced Css Search Box */
#advsearch {
text-align: center;
margin-top: 0px;
}
#advsearch input[type="text"] {
background: url(images/search-dark.png) no-repeat 10px 6px #fcfcfc;
border: 1px solid #d1d1d1;
font: bold 12px Arial,Helvetica,Sans-serif;
color: #bebebe;
width: 150px;
padding: 6px 15px 6px 35px;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
-moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15) inset;
-webkit-transition: all 0.7s ease 0s;
-moz-transition: all 0.7s ease 0s;
-o-transition: all 0.7s ease 0s;
transition: all 0.7s ease 0s;
}
#advsearch input[type="text"]:focus {
width: 200px;
}
答案 0 :(得分:2)
看起来你有一个分层问题 - 输入字段周围的框实际上扩展了整个屏幕宽度,位于菜单前面,因此你无法“到达”菜单。
轻松修复,只需在#advsearch
上设置宽度,然后将其设为更高z-index
。像这样:
#advsearch {
text-align: center;
margin: 20px auto 0px;
width:250px;
position:relative;
z-index:100;
}
我还添加了一个高于-1的z-index到#cssmenu
(我使用z-index:50;
),因为-1使得菜单在大多数浏览器上都无法使用。
答案 1 :(得分:1)
首先正确关闭你的html标签。
你错过了li和ul关闭标签。
</li>
</ul>
关闭此标签之前
更改以下css :(添加padding-top:20px;)
#cssmenu { position:fixed; left: 0;
padding-top:25px;
top: 0; width: 100%; z-index:-1;
}
答案 2 :(得分:1)
更新了你的jsfiddle。见Updated JSFiddle
代码更改。已将margin-left: 50px;
添加到#advsearch
#advsearch {
text-align: right;
margin-left: 50px;
margin-top: 20px;
}