0

我的 html/css 代码干扰了我的HTML/CSS下拉菜单

我的导航栏上方有一个文本框,但我的 CSS 下拉菜单担心 CSS 代码。

JSFIDDLE

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;
}
4

3 回答 3

2

看起来您遇到了分层问题 - 输入字段周围的框实际上扩展了整个屏幕宽度并且位于菜单前面,因此您无法“进入”菜单。

容易修复,只需设置一个宽度#advsearch并给它一个更高的z-index. 像这样:

#advsearch {
    text-align: center;
    margin: 20px auto 0px;
    width:250px;
    position:relative;
    z-index:100;
}

#cssmenu我还向(我使用了)添加了高于 -1 的 z-index,z-index:50;因为 -1 使菜单在大多数浏览器上无法使用。

工作示例:http: //jsfiddle.net/daCrosby/K6fey/3/

于 2013-06-07T03:24:51.077 回答
1

已更新您的 jsfiddle。请参阅更新的 JSFiddle

代码更改。添加margin-left: 50px;#advsearch

#advsearch {
    text-align: right;
    margin-left: 50px;
    margin-top: 20px;
}
于 2013-06-07T03:27:01.917 回答
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;
}
于 2013-06-07T03:21:44.613 回答