【问题标题】:How to create a side menu on hover on list items如何在列表项上悬停时创建侧边菜单
【发布时间】:2015-09-17 05:03:50
【问题描述】:

我目前有这样的下拉菜单:

我希望如果下拉列表中的每个列表项(例如 ASPIRE 等)从第一个下拉列表等中单击这些项目时在侧面有另一个下拉列表。就像单击 ASPIRE 时一样,旁边会出现另一个下拉菜单。 怎么做?

这是我的代码:

CSS 部分:

@import url(http://fonts.googleapis.com/css?family=Open+Sans:400,600,300);
@charset "UTF-8";
/* Base Styles */
#cssmenu,
#cssmenu ul,
#cssmenu li,
#cssmenu a {


margin: 0;
  padding: 0;
  border: 0;
  list-style: none;
  font-weight: normal;
  text-decoration: none;
  line-height: 1;
  font-family: 'Open Sans', sans-serif;


font-size: 14px;
  position: relative;
}
#cssmenu a {
  line-height: 1.3;
}

#cssmenu {
  width: 300px;
 margin-left: 90px;  background: #A3FFFF;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 3px;
  padding: 3px;


 -moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.6);
  -webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.6);
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.6);
}


#cssmenu > ul > li {
  margin: 0 0 3px 0;
}
#cssmenu > ul > li:last-child {
  margin: 0;
}
#cssmenu > ul > li > a {
  font-size: 15px;
  display: block;
  color: 

#ffffff;
  text-shadow: 0 1px 1px #000;
  background: #A3FFFF;
  background: -moz-linear-gradient(#565656 0%, #323232 100%);
  background: -webkit-gradient

(linear, left top, left bottom, color-stop(0%, #565656), color-stop(100%, #323232));
  background: -webkit-linear-gradient(#565656 0%, #323232 100%);


background: linear-gradient(#565656 0%, #323232 100%);
  border: 1px solid #000;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;
  border-radius: 4px;
}
#cssmenu > ul > li > a > span {
  display: block;
  border: 1px solid #666666;
  padding: 6px 10px;
  -webkit-border-radius: 4px;
  -moz-border-radius: 4px;


border-radius: 4px;
  font-weight: bold;
}
#cssmenu > ul > li > a:hover {
  text-decoration: none; font-weight: bold;
}
#cssmenu > ul > li.active {
  border-bottom: 

none; 
}
#cssmenu > ul > li.active > a {
  background: #47A3FF;
  background: -moz-linear-gradient(#47A3FF 0%, #47A3FF 100%);
  background: -webkit-gradient

(linear, left top, left bottom, color-stop(0%, #47A3FF), color-stop(100%, #47A3FF));
  background: -webkit-linear-gradient(#47A3FF 0%, #47A3FF 100%);


background: linear-gradient(#47A3FF 0%, #47A3FF 100%);
  color: #fff;
  text-shadow: 0 1px 1px #fff;
  border: 1px solid #47A3FF;
}
#cssmenu > ul > li.active > a 

span {
  border: 1px solid #47A3FF;
}
#cssmenu > ul > li.has-sub > a span {
  background: url(images/icon_plus.png) 98% center no-repeat;
}
#cssmenu > ul > li.has

-sub.active > a span {
  background: url(images/icon_minus.png) 98% center no-repeat;
}

/* Sub menu */
#cssmenu ul ul {
  padding: 5px 12px;
  display: none;
}
#cssmenu ul ul li {
  padding: 3px 0;
}
#cssmenu ul ul a {
  display: block;
  color: #191975;


font-size: 13px;
  font-weight: bold;
}
#cssmenu ul ul a:hover {
  color: cornflowerblue; font-weight:bold;
}

Javascript:

( function( $ ) {
$( document ).ready(function() {
$('#cssmenu > ul > li > a').click(function() {
  $('#cssmenu li').removeClass('active');
  $(this).closest('li').addClass('active'); 
  var checkElement = $(this).next();
  if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
    $(this).closest('li').removeClass('active');
    checkElement.slideUp('normal');
  }
  if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
    $('#cssmenu ul ul:visible').slideUp('normal');
    checkElement.slideDown('normal');
  }
  if($(this).closest('li').find('ul').children().length == 0) {
    return true;
  } else {
    return false;   
  }     
});
});
} )( jQuery );

HTML:

<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
   <script src="script.js"></script>

<div id='cssmenu'>
<ul>



<li class='has-sub'><a href='#'><span>CENTRAL COMPLIANCE</span></a>

<ul>

<li><a href='#'><span>ASPIRE</span></a></li>

<hr>     
<li><a href='#'><span>CRRMS</span></a></li>  
<hr>
<li><a href='#'><span>Employee Accounts</span></a></li>
<hr> 
<li><a href='#'><span>Future Ethics Training</span></a></li>
<hr>
<li><a href='#'><span>GEPOC</span></a></li>
<hr>
<li><a href='#'><span>Global Registration</span></a></li>
<hr>
<li><a href='#'><span>MBL</span></a></li>
<hr>
<li><a href='#'><span>Account Affirmations</span></a></li>

<hr>       
<li class='last'><a href='#'><span>Outside Affiliations</span></a></li>

</ul>

</li>

<li class='has-sub'><a href='#'><span>CONTROL ROOM</span></a>

<ul>

<li><a href='#'><span>CDS</span></a></li>

<hr>
<li><a href='#'><span>UK Registration</span></a></li>
 <hr><li class='last'><a href='#'><span>Compliance Portal</span></a></li>

</ul>

</li>


<li class='has-sub'><a href='#'><span>LARGE HOLDINGS</span></a>

<ul>
         <li class='last'><a href='#'><span>LHO</span></a></li>

</ul>

</li>


<li class='has-sub'><a href='#'><span>ORCHESTRIA</span></a>

<ul>
         <li class='last'><a href='#'><span>Orchestria</span></a></li>

</ul>

</li>
 </ul></div>

【问题讨论】:

  • 其中提供的答案不适用于我的情况。
  • 您是否必须更正您的代码,或者您能否实施新的解决方案?我还是发布了一个新的解决方案。
  • 哦,我想更正我的代码

标签: javascript html css


【解决方案1】:

看看这个,你可以随心所欲地设计它,它完美地工作:

http://slicknav.com/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多