下拉菜单中的点击行为不一致

时间:2016-04-30 22:22:48

标签: html css drop-down-menu menu

我发现此代码在我的网站上创建了一个CSS下拉菜单。但是,点击行为不一致。有时候它会连续几次工作,然后有时它甚至无法工作,即使我点击同一个区域。我有什么办法可以让这项工作变得更好吗?

HTML:

 <form class="searchbox" action="">
    <input type="search" placeholder="search.." />
    <ul class="suggestions">
        <li><a href="/about">About</a></li>
        <li><a href="/intro">Home</a></li>
        <li><a href="/video-games">Video Games</a></li>
        <li><a href="/theatre">Theatre</a></li>
    </ul>
</form>

CSS:

body{
/*changing background color*/
background-color:#ebebeb;
}
.searchbox{
/*definint width of form element*/
    width:350px;
/*centering the form element*/
    margin:100px auto;
}
input[type="search"]{
    padding:10px 15px 10px 50px;
    font-size:36px;
    color:#1f5350;
/*removing boder from search box*/
    border:none;
/*defining background image as a search symbol*/
    background-color:#7accc8;
}
/*now using placeholder property to change color of placholder text and making it consitent accross the browser by use of prefix*/
input[type="search"]::-webkit-input-placeholder{
    color:#b1e0de;
}
input[type="search"]:-moz-placeholder { /* Firefox 18- */
   color: #b1e0de;
}
input[type="search"]::-moz-placeholder {  /* Firefox 19+ */
   color: #b1e0de;
}
input[type="search"]:-ms-input-placeholder {  /* interner explorer*/
   color: #b1e0de;
}
.searchbox a{
    display:block;
/*removing underlines from anchor element*/
    text-decoration:none; 
    color:#1f5350;
    font-size:30px;
    background-color:#ace5e2;
    padding:10px;
}
.searchbox ul{
/*removing predefined bullet points from list*/
    list-style:none;
/*removing padding from list items*/
    padding:0;
     width:465px;
}
.searchbox ul li{
    margin-bottom:10px;
}
/*adding effect when the mouse is hovered over list item*/
.searchbox ul li a:hover{
    color:#b23b61;
    background:#ecd1da;
}
/*moving it slightly toware right when hovered*/
.searchbox ul li:hover{
/*transform*/
-webkit-transform:translateX(20px);
   -moz-transform:translateX(20px);
    -ms-transform:translateX(20px);
     -o-transform:translateX(20px);
        transform:translateX(20px);
}
/*now first we will hide the suggestion list*/
.suggestions li{
    overflow:hidden;
    height:0;
    -webkit-transition:all 0.3s ease-in-out;
   -moz-transition:all 0.3s ease-in-out;
     -o-transition:all 0.3s ease-in-out;
        transition:all 0.3s ease-in-out;
}
/*and make the suggestion reappear when user focus on search field*/
input[type="search"]:focus + .suggestions li{
    height:63px;
}

.byline{
  text-align:center;
  font-size:18px;
}
.byline a{
  text-decoration:none;
  color: #1f5350;
}

谢谢!

1 个答案:

答案 0 :(得分:0)

您的网站是否使用Bootstrap和jQuery?我曾经遇到过这个问题,所有我必须做的就是在包含我的Bootstrap文件之前包含我的jQuery文件,如下所示:

<script type="text/javascript" src="js/jquery-X.X.X.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>

此外,如果您使用的是Bootstrap,请检查您是否在不同的地方多次包含它。