响应式下拉点击/悬停

时间:2014-07-30 12:37:33

标签: jquery html css3 drop-down-menu hover

我目前正在编写我的第一个响应式网站(我是一般的初学者),我偶然遇到了很多障碍。其中一个是我的菜单问题。我会尝试尽可能具体。 我有一个桌面水平菜单和平板电脑/手机垂直菜单。我不知道如何解决在tab / mob版本中悬停的问题。我有一个小的切换脚本用于为下拉菜单设置动画,但是每次单击或悬停时它都会下降。如何禁用悬停?我想完全删除我网站上的悬停,但我不知道如何设置下拉风格。我想我已经尝试了一切。我也很感激帮助我完成脚本。我将不胜感激任何帮助。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $(".navbar li").click(function(){
  $("li.nav_slide").slideToggle("fast");
  });
});
</script>



    <body>
    <div class="container">
    <nav>
    <ul class="navbar"> 
      <li><a href='#'><span aria-hidden="true" data-icon="&#xe600;" class="icon-home"></a></li> 
      <li><a href="sub/who_we_are.hmtl/">WHO WE ARE</a></li> 
      <li><a href="#">WHAT WE DO</a>
        <ul>
          <li class="nav_slide"><a href="sub/club_nights.html/">CLUB NIGHTS</a></li>
          <li class="nav_slide"><a href="sub/festivals.html/">FESTIVALS</a></li>
        </ul> 
      </li>
      <li><a href="#">WHAT WE OFFER</a> 
        <ul>
          <li class="nav_slide"><a href="sub/full_system.html/">FULL SYSTEM</a></li>
          <li class="nav_slide"><a href="sub/individual_eq.html/">INDIVIDUAL EQ</a></li>
        </ul>
     </li>
     </ul>
     </nav>
     </div>
     </body>
<!--desktop-->
  .container {
  position: relative;
  top: 0;
  left: 0;
  width: 800px;
  height: 600px;
  max-width: 1500px;
  background-image: url('home.jpg');
  background-repeat: no-repeat;
  background-position: center;
  margin: 0 auto 0 auto;
}

nav {  
  position: relative;
  top: 430px;
  left: 0;
  margin: 0 auto 0 auto;
  width: 600px;  
  height: 25px;
  font-size: 15px;    
}  

nav ul {  
  position: relative;
  top: 0;
  left: 40px;
  float: left;
  height: 100%;
  width: 100%;
  list-style: none;
}  

nav li { 
  position: relative;
  display: inline;
  padding: 0;  
  width: 135px;
  float: left;
  text-align: center;
}  

nav li:first-child {
  width: 30px;
}

li.menu_icons {
  width: 80px;
  text-align: right;
}

ul li a{
  display: inline;
  text-decoration: none;
}

ul li a:hover{
  font-size: 16px;
  text-align: center;
}

ul li ul{
  display: none;
}

ul li:hover ul{
  display: block; /* display the dropdown */
  float: none; 
  background-color: #813C7D;
  width: 135px;
  position: relative;
  top: 0;
  left: 0;
}

ul li:hover li{
 width: 100%;
 background-color: #813C7D;
 padding: 5px 5px 5px 5px;
}

li:hover li:last-child {
 padding-bottom: 10px;
}

ul li:hover li a {
  width: 100%;
  text-align: center;
}

nav li a {   
  box-sizing:border-box;  
  -moz-box-sizing:border-box;  
  -webkit-box-sizing:border-box;  
}

/* unvisited link */
a:link { color: white; }
/* visited link */
a:visited { color: white; }
/* selected link */
a:active { color: white; font-weight: bold; }

a:link { text-decoration: none; }
a:hover {text-decoration: none; }
a:visited { text-decoration: none; }
a:active{ text-decoration: none; }
}
}

<!--tab/mob-->


   .container {
  width: 100%;
  max-width: 600px;
}

nav {  
  position: static;
  width: 100%;  
  background: none; 
  font-size: 15px;   
  height: auto; 
}  

nav ul {  
  position: relative;
  top: 0; 
  left: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  background-color: #813C7D;
}  

nav li { 
  padding: 0.25em 0;
  text-align: center;
  width: 100%;
}

nav li:first-child {
  display: none;
}

nav li ul:first-child {
  display: block;
}

ul li a{
  text-decoration: none;
}

ul li ul li a{
  text-align: center;
  width: 100%;
}

.nav_slide {
  width: 100%;
  display: none;
}
}

2 个答案:

答案 0 :(得分:0)

尝试删除所有拥有:Hover

的CSS

这会产生这样的结果:(它是否按预期工作?)

  .container {
  position: relative;
  top: 0;
  left: 0;
  width: 800px;
  height: 600px;
  max-width: 1500px;
  background-image: url('home.jpg');
  background-repeat: no-repeat;
  background-position: center;
  margin: 0 auto 0 auto;
}

nav {  
  position: relative;
  top: 430px;
  left: 0;
  margin: 0 auto 0 auto;
  width: 600px;  
  height: 25px;
  font-size: 15px;    
}  

nav ul {  
  position: relative;
  top: 0;
  left: 40px;
  float: left;
  height: 100%;
  width: 100%;
  list-style: none;
}  

nav li { 
  position: relative;
  display: inline;
  padding: 0;  
  width: 135px;
  float: left;
  text-align: center;
}  

nav li:first-child {
  width: 30px;
}

li.menu_icons {
  width: 80px;
  text-align: right;
}

ul li a{
  display: inline;
  text-decoration: none;
}

ul li ul{
  display: none;
}

nav li a {   
  box-sizing:border-box;  
  -moz-box-sizing:border-box;  
  -webkit-box-sizing:border-box;  
}

/* unvisited link */
a:link { color: white; }
/* visited link */
a:visited { color: white; }
/* selected link */
a:active { color: white; font-weight: bold; }

a:link { text-decoration: none; }
a:hover {text-decoration: none; }
a:visited { text-decoration: none; }
a:active{ text-decoration: none; }


<!--tab/mob-->


   .container {
  width: 100%;
  max-width: 600px;
}

nav {  
  position: static;
  width: 100%;  
  background: none; 
  font-size: 15px;   
  height: auto; 
}  

nav ul {  
  position: relative;
  top: 0; 
  left: 0;
  width: 100%;
  margin: 0;
  padding: 0;
  background-color: #813C7D;
}  

nav li { 
  padding: 0.25em 0;
  text-align: center;
  width: 100%;
}

nav li:first-child {
  display: none;
}

nav li ul:first-child {
  display: block;
}

ul li a{
  text-decoration: none;
}

ul li ul li a{
  text-align: center;
  width: 100%;
}

.nav_slide {
  width: 100%;
  display: none;
}

答案 1 :(得分:0)

从头开始创建响应式导航栏可能会非常麻烦。

这并不能完全回答你的问题,但如果你不想自己做肮脏的工作,我的建议是使用eg。 Bootstrap的导航栏组件 http://getbootstrap.com/components/#navbar