使用CSS调整JQuery菜单宽度时出现问题

时间:2011-02-05 22:39:49

标签: jquery css

我在尝试调整我从这里下载的这个JQuery菜单的某些项目的宽度时遇到了一些问题:http://apycom.com/menus/6-midnight-blue.html

CSS非常复杂,但我能够缩小整个菜单的宽度,但其他部分很难追踪。

我希望菜单的整体宽度与其下方标记的红色Div大小相同。

滑块本身 - 当您将鼠标悬停在主菜单项上时会移动太宽,我不知道如何调整它。

最后一个菜单项“请求估计”似乎根本没有填充,与其他菜单项相比,它看起来很局促。这是拼写最长的单词,这就是原因,但我想找出一种方法来略微缩小其他主菜单项宽度的大小。

子菜单框几乎是主菜单项宽度的两倍,我不知道如何减小宽度。

凭借有限的CSS知识,我似乎搞砸了事情,而不是修理任何东西。

对此的任何帮助将不胜感激。

这是随JQuery下载附带的CSS,我已对此进行了调整:

/* menu::base */
div#menu {
    height: 51px;
    padding-left: 14px;
    background: url(images/left.png) no-repeat;
    _background: url(images/left.gif) no-repeat;
    width:auto;    
}

div#menu ul {
    margin: 0;
    padding: 0;
    list-style: none;
    float: left;
}
div#menu ul.menu {
    padding-right: 14px;
    background: url(images/right.png) no-repeat right 0;
    _background: url(images/right.gif) no-repeat right 0;    
}

div#menu li {
    position: relative;
    margin: 0;
    padding: 0 0px 0 0;
    /*background: green;*/
    display: block;
    float: left;
    z-index: 9;
    width: auto;
}
div#menu ul ul li {
    z-index: 9;
}
div#menu li div {
    list-style: none;
    float: left;
    position: absolute;
    z-index: 11;
    top: 51px;
    left: -3px;
    visibility: hidden;
    width: 194px;
    margin: 0px 0 0 -4px;
    padding: 0; 
    background: url(images/subsubmenu-top.png) no-repeat 0px 0;
    _background: url(images/subsubmenu-top.gif) no-repeat 0px 0;  
}
div#menu ul ul {
    z-index: 12;
    padding: 0px 4px 10px 4px;
    background: url(images/submenu-bottom.png) no-repeat 0px bottom;
    _background: url(images/submenu-bottom.gif) no-repeat 0px bottom;        
    margin: 10px 0 0 0;    
}
div#menu li:hover>div {
    visibility: visible;
}

div#menu a {
    position: relative;
    z-index: 10;
    height: 50px;
    display: block;
    float: left;
    line-height: 50px;
    text-decoration: none;
    margin-top: 1px;
    white-space: nowrap;
    /*width: auto;*/
    width: 90px; /*adjust overal menu width*/
    padding-right:5px;
    text-align:center;
}
div#menu span {
    margin-top: 2px;
    /*padding-left: 15px;*/
    padding-left: 2px;
    color: #A6C4D5;
    font: bold 12px Arial,Helvetica;
    background: none;
    line-height: 50px;  
    display: block;
    cursor: pointer;
    background-repeat: no-repeat;
    background-position: 95% 0;
    text-align: center;
}

/* menu::level1 */
div#menu a {
    padding: 0 10px 0 0;
    line-height: 50px;
    height: 51px;
    margin-right: 5px;
    _margin-right: 1px;
    background: none;
}
div#menu a:hover {
    background:  url(images/selected.png)  repeat-x right -1px;
    color: #FFFFFF;
}
div#menu li.current a,
div#menu ul.menu>li:hover>a {
    color: #FFFFFF; 
    background: url(images/selected.png)  repeat-x right -1px;
}

div#menu ul.menu>li:hover>a span {
    color: #FFFFFF;
}
div#menu li {  }
div#menu li.last { background: none; }

/* menu::level2 */
div#menu ul ul li {
    background: none;
    padding: 0;
}
div#menu ul ul a {
    padding: 0px;
    height: auto;
    float: none;
    display: block;
    line-height: 25px;
    z-index: -1;
    padding-left: 5px;
    white-space: normal;
    width: 164px;
    margin: 0 8px;
    text-transform: none;
    border-top: 1px solid #3A5A8B;
    border-bottom: 1px solid #162133;        
}

div#menu ul ul a span {
    font-weight:normal;
    padding: 0 5px;
    line-height: 25px;
    font-size: 12px;
    color: #C5D3E7;
}
div#menu li.current ul a,
div#menu li.current ul a span {
    background:none;
}
div#menu ul ul a:hover {
    background:none;
    background-color: #21345A;
}
div#menu ul ul a:hover span {
background:none;
color: #FFFFFF;
}
div#menu ul ul a.parent {
    background: url(images/submenu-pointer.png) no-repeat right bottom;
    _background: url(images/submenu-pointer.gif) no-repeat right bottom;  
}
div#menu ul ul a.parent span {
    background:none; 
}
div#menu ul ul a.parent:hover {
    background: url(images/submenu-pointer.png) no-repeat right bottom;
    _background: url(images/submenu-pointer-hover.gif) no-repeat right bottom;
    background-color: #21345A;
    color: #FFFFFF;  
}
div#menu ul ul a.parent:hover span {
    background:none; 
}
div#menu ul ul span {
    margin-top: 0;
    text-align: left;
}
div#menu ul ul li.last { background: none; }
div#menu ul ul li {
    width: 100%;
}

/* menu::level3 */
div#menu ul ul div {
    /*width: 194px;*/
    padding: 0;
    margin: -51px 0 0 192px !important;
    margin-left: 192px;
}
div#menu ul ul ul {
    padding: 10px 4px 0 4px;    
}
div#menu ul ul div li {
    position:relative;
    top:-10px;
}

/* lava lamp */
div#menu li.back {
    background: url(images/selected.png) repeat-x 0 0;
    width: 5px;
    height: 51px;
    z-index: 8;
    position: absolute;
    padding: 0;
    margin: 0px 0 0 0;
} 

div#menu li.back .left {
    padding:0;
    width:auto;
    background: url(images/selected.png) repeat-x right 0;
    height: 51px;
    margin: 0 0 0 5px;
    float: none;
    position: relative;
    top: 0;
    left: 0;
    visibility: visible;
}

这是HTML:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="DaVincisApp1.WebForm1" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="menu.css" rel="Stylesheet" type="text/css" />
    <script type="text/javascript" src="Scripts/jquery.js"></script>
    <script type="text/javascript" src="Scripts/menu.js"></script>
</head>
<body>
    <form id="form1" runat="server">
   <div style="margin-left:1em; margin-top:5em;">
        <div id="menu">
       <ul class="menu">
           <li><a href="#" class="parent"><span>Home</span></a>
      <div><ul>
         <li><a href="#" class="parent"><span>Sub Item 1</span></a>
        <div><ul>
           <li><a href="#" class="parent"><span>Sub Item 1.1</span></a>
           <div><ul>
              <li><a href="#"><span>Sub Item 1.1.1</span></a></li>
              <li><a href="#"><span>Sub Item 1.1.2</span></a></li>
           </ul></div>
           </li>
           <li><a href="#"><span>Sub Item 1.2</span></a></li>
           <li><a href="#"><span>Sub Item 1.3</span></a></li>
           <li><a href="#"><span>Sub Item 1.4</span></a></li>
           <li><a href="#"><span>Sub Item 1.5</span></a></li>
           <li><a href="#"><span>Sub Item 1.6</span></a></li>
           <li><a href="#" class="parent"><span>Sub Item 1.7</span></a>
           <div><ul>
              <li><a href="#"><span>Sub Item 1.7.1</span></a></li>
              <li><a href="#"><span>Sub Item 1.7.2</span></a></li>
        </ul></div>
                     </li>
        </ul></div>
        </li>
        <li><a href="#"><span>Sub Item 2</span></a></li>
        <li><a href="#"><span>Sub Item 3</span></a></li>
    </ul></div>
    </li>
    <li><a href="#"><span>About Us</span></a>
       <div><ul>
       <li><a href="#" class="parent"><span>Our Core Values</span></a>
          <div><ul>
             <li><a href="#"><span>Sub Item 1.1</span></a></li>
        <li><a href="#"><span>Sub Item 1.2</span></a></li>
          </ul></div>
        </li>
        <li><a href="#" class="parent"><span>Company History</span></a>
           <div><ul>
        <li><a href="#"><span>Sub Item 2.1</span></a></li>
        <li><a href="#"><span>Sub Item 2.2</span></a></li>
           </ul></div>
        </li>
        <li><a href="#"><span>Our Process</span></a></li>
        <li><a href="#"><span>Our Credentials</span></a></li>
        <li><a href="#"><span>Our Guarantee</span></a></li>
        <li><a href="#"><span>Why DaVinci's</span></a></li>
        </ul></div>
    </li>
    <li><a href="#"><span>Services</span></a>
                  <div><ul>
                     <li><a href="#"><span>Residential</span></a></li>
                     <li><a href="#"><span>Faux Painting</span></a></li>
                     <li><a href="#"><span>Wallpaper Services</span></a></li>
                     <li><a href="#"><span>Commercial</span></a></li>
                     <li><a href="#"><span>Drywall Services</span></a></li>
                     <li><a href="#"><span>Powerwashing</span></a></li>
                     <li><a href="#"><span>Painter-For-A-Day</span></a></li>
                     <li><a href="#"><span>Priority Service</span></a></li>
                  </ul></div>
               </li>
    <li><a href="#"><span>Porfolio</span></a>
                  <div><ul>
                     <li><a href="#"><span>Interior Gallery</span></a></li>
                     <li><a href="#"><span>Exterior Gallery</span></a></li>
                     <li><a href="#"><span>Faux Gallery</span></a></li>
                     <li><a href="#"><span>Commercial Jobs</span></a></li>
                  </ul></div>
              </li>
              <li><a href="#"><span>Testimonials</span></a></li>
    <li><a href="#"><span>Client Area</span></a>
                  <div><ul>
                     <li><a href="#"><span>Start-up Guide</span></a></li>
                     <li><a href="#"><span>Color Selector</span></a></li>
                     <li><a href="#"><span>Painting Facts</span></a></li>
                     <li><a href="#"><span>Paint Glossary</span></a></li>
                     <li><a href="#"><span>Jobsite Safety</span></a></li>
                     <li><a href="#"><span>Forms/ Checklists</span></a></li>
                     <li><a href="#"><span>Online Payment</span></a></li>
                     <li><a href="#"><span>Privacy Policy</span></a></li>
                  </ul></div>
               </li>
    <li class="last"><a href="#"><span>Request Estimate</span></a></li>
        </ul>
</div>
</div>
<br /><br /><br />
<div style="width:44em; margin-left:1em; background-color:red">About this size</div>
<a href="http://apycom.com/"></a>
</form>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

  

我想拥有整体菜单   宽度与红色大致相同   Div标在它下面。

只需给你的div#menu和红色div一样的witdh。并设置为div#menu ul.menu100%

  

子菜单框几乎是两倍   主菜单项的宽度,和我   不知道如何减小宽度   对此。

嵌套菜单项的宽度可在div#menu li div中更改。根据您的需要设置宽度。请注意,您还必须修改div#menu ul ul a

的宽度

可以在此处查看基于您的代码的工作解决方案:http://jsfiddle.net/xPkcZ/1/

注意:在某些背景属性中,我添加了背景色,如#ddd,以获得更好的视图效果,因为背景图片可用。

答案 1 :(得分:0)

我发现菜单的主要级别有1个宽度问题,而且每个项目都有滑块。

div#menu li {
position: relative;
margin: 0;
padding: 0 0px 0 0;
/*background: green;*/
display: block;
float: left;
z-index: 9;
/*width: auto;*/
width: 100px; /*adjust width for each Level1 item*/
}

现在我正在为主菜单下面的子菜单寻找解决方案