1

我想保持菜单文本按原样缩进,但是我希望出现在悬停上的栏一直向左延伸,就像它向右一样,所以没有边距(现在有左边有一个缺口)。这可能吗?

赞赏。

jsfiddle:http: //jsfiddle.net/xcgjR/29/

CSS

    body {
    background-color: #cccccc;
    }

#mainmenu {
  margin: 0;
  list-style-type: none;
  position: relative;  
     padding-left: 60;
  }

#mainmenu li {
  clear: left;
   position:relative;
   }

#mainmenu a {
  display: block;
  overflow: hidden;
  float: left;
 width:100%;
  position:relative;
    opacity: 1;
    -webkit-transition: all 0.4s ease-in-out;
    padding-left:32px;
    line-height: 42px;
}

#mainmenu > li:hover > a {
  background-position: 0 0;
  background-color:clear;
  background-color:rgba(255,255,255,0.5);
   width:100%;
   \
 opacity: 0;
    -webkit-transition: none;
}

#mainmenu li.active a {
  background-position: 0 0;
  background-color:clear;
    width:100%;  
}

.submenu {
  list-style-type: none; 
  float: left;
  display: none;
  position:absolute;
  left: 90px;
  top:0px;
  width: auto;
}

#mainmenu li a:hover + .submenu, .submenu:hover {
  display:block;
} 

.submenu li {
  display: inline-block; 
  clear: none !important;
}

.submenu li a {
  float: right;
  margin-left: 10px;  
}


/*repeat each of these with new name like submenu3 or submenu4, when adding a new submenu */

.submenu2 {
  list-style-type: none; 
  float: left;
  display: none;
  position:absolute;
  left: 86px;
  top:0px;
  width: auto;
}


#mainmenu li a:hover + .submenu2, .submenu2:hover {
  display:block;
} 

.submenu2 li {
  display: inline-block; 
  clear: none !important;
}

.submenu2 li a {
  float: right;
  margin-left: 10px;  
}


/*end of codes that need to be copied when adding a new submenu*/ 

.maintextcolour {
    font-family: LetterGothic, Arial, Helvetica, sans-serif;
    font-size: 12px;
    color:#FFF;
    text-decoration: none;
    padding-top:11px;
    cursor: url(cart3.png), auto;
}


.subtextcolour {
    font-family: LetterGothic, Arial, Helvetica, sans-serif;
    font-size: 12px;
    color:#FFF;
    text-decoration: none;
    padding-top:11px;
    cursor: url(cart3.png), auto;
}

.subtextcolour:hover {
    font-family: LetterGothic, Arial, Helvetica, sans-serif;
    font-size: 12px;
    color:#666;
    text-decoration: none;
    padding-top:11px;
    cursor: url(cart3.png), auto;
}

#container {
    position: relative;
    min-height: 100%;   
}


@font-face {
    font-family: LetterGothic;
    src: url('LetterGothicStd.otf');
}

HTML

<body>

<div id="container">

<header>

<div align="left">
<a href="Kelly5.html" style="text-decoration:none"><span class="headertext">title </span>
<span class="headertextgreen">HERE</span></a><p><br /></div>

</header>


<nav>
     <ul id="mainmenu">

       <li id="liHome"><a href="#item-x1y1" class="maintextcolour" rel="none" id="Home">INFO</a></li>


        <li id="liServices" class="active"><a href="#item-x1y2" class="maintextcolour" rel="SubMenuY2" id="Services">EXHIBITIONS</a>
             <ul id="SubMenuY2" class="submenu">
                 <li><a href="current.html" class="subtextcolour">CURRENT</a></li>
                 <li><a href="previous.html" class="subtextcolour">PREVIOUS</a></li>     
             </ul></li>


         <li id="liEnvironment">
             <a href="#item-x1y3" class="maintextcolour" rel="none" id="Environment">CV</a>
         </li> 


</nav>

     </div>

</body>
4

1 回答 1

1

是的是可能的。首先,您需要从标签中删除默认填充,然后将其添加到超链接标签中,以便它以全宽显示。还有代码:

http://dabblet.com/gist/6077264

#mainmenu {
 margin: 0;
 list-style-type: none;
 position: relative;  
 padding-left: 0;
}

#mainmenu a {
 display: block;
 overflow: hidden;
 float: left;
 width:100%;
 position:relative;
 opacity: 1;
 -webkit-transition: all 0.4s ease-in-out;
 line-height: 42px;
 padding-left:32px; /* add as many pixels here! as you want */
}

希望能帮助到你!

于 2013-07-25T06:08:38.327 回答