Superfish菜单垂直向左开放?

时间:2013-12-06 08:49:02

标签: jquery css superfish

我正在尝试垂直使用Superfish,但是在页面右侧对齐,从而打开左侧的任何子菜单。我一直在调整一些CSS属性来实现这一点,但它不能完美地工作 - 箭头总是位于任何父菜单文本的右侧,在这种情况下,它们应该在文本的左侧,并且子菜单的位置为左侧在2级和3级中的工作方式不完全相同!

这让我抓狂!有人完成了这项工作吗?任何提示或示例?

提前致谢, LM

[编辑]

我设法将箭头放在左边(在CSS [大写我的编辑:...中]注释,并设法打开左边的子菜单(使用最新版本的SuperFish与类.sf-vertical)但我'我仍然遇到第3级子菜单问题 - 阴影错位!

这里是html页面和我改变的CSS代码('superfish.css'中的箭头和'superfish-vertical.css'中的位置:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
  <link media="screen" rel="stylesheet" href="_assets/superfish.css" />
  <link media="screen" rel="stylesheet" href="_assets/superfish-vertical.css" />
  <script type="text/javascript" src="_assets/jquery-1.10.2.min.js" charset="utf-8"></script>
  <script type="text/javascript" src="_assets/superfish.js"></script>
  <script type="text/javascript" src="_assets/hoverIntent.js"></script>
  <script type="text/javascript" src="_assets/supersubs.js"></script>
</head>
<body style="margin: 0;">

 <div style="width: 150px; position: absolute; top: 0px; right: 200px; background: #CCC;">
   <ul class="sf-menu sf-vertical" id="myMenu">
     <!--MENU-01-->
     <li><a href="#"><b>MENU-1</b></a></li>
     <!--MENU-02-->
     <li><a href="#"><b>MENU-2</b></a></li>
     <!--MENU-03-->
     <li>
       <a href="javascript:void(0);"><b>MENU-3</b></a>
       <ul>
         <li><a href="#">MENU-3.1</a></li>
         <li>
           <a href="javascript:void(0);">MENU-3.2</a>
           <ul>
             <li><a href="#">MENU-3.2.1</a></li>
             <li><a href="#">MENU-3.2.2</a></li>
             <li><a href="#">MENU-3.2.3</a></li>
             <li><a href="#">MENU-3.2.4</a></li>
           </ul>
         </li>
       </ul>
     </li>
     <!--MENU-04-->
     <li><a href="#"><b>MENU-4</b></a></li>
   </ul>
 </div>

 <script type="text/javascript">
 $(document).ready(function () {
   $('ul.sf-menu').supersubs({
     minWidth:'150px', maxWidth: '150px', extraWidth: 0
   }).superfish();
 });
 </script>

</body>
</html>

superfish.css

/*** ESSENTIAL STYLES ***/
.sf-menu, .sf-menu * {
    margin: 0;
    padding: 0;
    list-style: none;
    font-family: Arial, Helvetica, Sans-Serif; font-size: 12px; color: #FFFFFF;
}
.sf-menu li {
    position: relative;
}
.sf-menu ul {
    position: absolute;
    display: none;
    top: 100%;
    left: 0;
    z-index: 99;
}
.sf-menu > li {
    float: left;
}
.sf-menu li:hover > ul, .sf-menu li.sfHover > ul {
    display: block;
}

.sf-menu a {
    display: block;
    position: relative;
}
.sf-menu ul ul {
    top: 0;
    left: 100%;
}


/*** DEMO SKIN ***/
.sf-menu {
    float: left;
    margin-bottom: 1em;
}
.sf-menu ul {
    box-shadow: 2px 2px 6px rgba(0,0,0,0.2);
    min-width: 12em; /* allow long menu items to determine submenu width */
    *width: 12em; /* no auto sub width for IE7, see white-space comment below */
}
.sf-menu a {
    /*border-left: 1px solid #fff;*/
    border-top: 1px solid #dFeEFF; /* fallback colour must use full shorthand */
    border-top: 1px solid rgba(255,255,255,0.5);
    padding: .75em 1em;
    text-decoration: none;
    zoom: 1; /* IE7 */
}
.sf-menu a {
    color: #13a;
}
.sf-menu li {
    background: #BDD2FF;
    white-space: nowrap; /* no need for Supersubs plugin */
    *white-space: normal; /* ...unless you support IE7 (let it wrap) */
    -webkit-transition: background .2s;
    transition: background .2s;
}
.sf-menu ul li {
    background: #AABDE6;
}
.sf-menu ul ul li {
    background: #9AAEDB;
}
.sf-menu li:hover, .sf-menu li.sfHover {
    background: #CFDEFF;
    /* only transition out, not in */
    -webkit-transition: none;
    transition: none;
}

/*** arrows (for all except IE7) **/
.sf-arrows .sf-with-ul {
    padding-right: 2.5em;
    *padding-right: 1em; /* no CSS arrows for IE7 (lack pseudo-elements) */
}
/* styling for both css and generated arrows */
.sf-arrows .sf-with-ul:after {
    content: '';
    position: absolute;
    top: 50%;
    left: 2px; /* MY EDIT: PLACES ARROWS AT MOST LEFT, IT WORKS OK */
    margin-top: -3px;
    height: 0;
    width: 0;
    /* order of following 3 rules important for fallbacks to work */
    border: 5px solid transparent;
    border-top-color: #dFeEFF; /* edit this to suit design (no rgba in IE8) */
    border-top-color: rgba(255,255,255,0.5);
}
.sf-arrows > li > .sf-with-ul:focus:after,
.sf-arrows > li:hover > .sf-with-ul:after,
.sf-arrows > .sfHover > .sf-with-ul:after {
    border-top-color: white; /* IE8 fallback colour */
}
/* styling for right-facing arrows */
.sf-arrows ul .sf-with-ul:after {
    margin-top: -5px;
    margin-right: -3px;
    border-color: transparent;
    border-left-color: #dFeEFF; /* edit this to suit design (no rgba in IE8) */
    border-left-color: rgba(255,255,255,0.5);
}
.sf-arrows ul li > .sf-with-ul:focus:after,
.sf-arrows ul li:hover > .sf-with-ul:after,
.sf-arrows ul .sfHover > .sf-with-ul:after {
    border-left-color: white;
}

最后是superfish-vertical.css

/* adding sf-vertical class in addition to sf-menu creates a vertical menu */
/* eg. <ul class="sf-menu sf-vertical"> ... */
.sf-vertical {
    width: 150px;
/* If you want the width of the closed menu to expand to its
widest top-level menu item (like its "Supersubs" submenus do),
replace the width rule above with the following two rules. */

/*
min-width: 12em;
*width: 12em;
*/
}

.sf-vertical ul {
    left: -100%; /* MY EDIT: THIS WORKS OK AT 2nd LEVEL */
    top: 0;
}
.sf-vertical > li {
    float: none;
}
.sf-vertical li {
    width: 100%;
}

.sf-vertical ul ul li {
    left: -200%; /* MY EDIT: THIS WORKS OK AT 3rd LEVEL BUT SHADOW IS MISPLACED */
    top: 0;
}

/*** alter arrow directions ***/
.sf-vertical.sf-arrows > li > .sf-with-ul:after {
    margin-top: -5px;
    margin-right: -3px;
    border-color: transparent;
    border-left-color: #dFeEFF; /* edit this to suit design (no rgba in IE8) */
    border-left-color: rgba(255,255,255,0.5);
}
.sf-vertical.sf-arrows li > .sf-with-ul:focus:after,
.sf-vertical.sf-arrows li:hover > .sf-with-ul:after,
.sf-vertical.sf-arrows .sfHover > .sf-with-ul:after {
    border-left-color: white;
} 

2 个答案:

答案 0 :(得分:0)

您的第二个选择器正在选择<li>而不是<ul>(阴影所在的位置),请尝试;

.sf-vertical ul ul { /* removed trailing "li" selector */
    left: -100%; /* changed from 200% */
    top: 0;
}

演示于:http://jsfiddle.net/JvmFm/2/

答案 1 :(得分:0)

这个问题可能有些陈旧,但可能有所帮助,请尝试this jsfiddle

(function($) { //create closure so we can safely use $ as alias for jQuery
    $(document).ready(function() {
        // initialise plugin
        var example = $('.sf-menu').superfish({
            //add options here if required                  
        }).supposition();
    });
})(jQuery);