简体   繁体   English

菜单的伪下划线选择器

[英]Pseudo Underline Selector for menu

I have a horizontal list menu, on which I want to use pseudo selectors: When you hover over the menu item, it should have a thick color underline. 我有一个水平列表菜单,在该菜单上我想使用伪选择器:将鼠标悬停在菜单项上时,该菜单项应具有较深的颜色下划线。 Each Menu item have a different width and its underlining effect should match that width 每个菜单项都有不同的宽度,其下划线效果应与该宽度匹配

Here is a sample website with its underlining menus: http://www.theblackswantheory.org/ 这是一个带有下划线菜单的示例网站: http : //www.theblackswantheory.org/

Here is my list: 这是我的清单:

<div id="other">
  <div id="otherTable">
    <ul id="ul1">
        <li>Web Design</li>
        <li>Graphic Design</li>
        <li>Google Search Optimization</li>              
    </ul>
  </div>
</div>

CSS: CSS:

#otherTable{
    display: table;
    margin: 0 auto;
}
#otherTable ul{
    list-style: none;
}
#otherTable ul li{
    display: inline;
    margin: 10px;
}
ul#ul1{
    color: #fff;
}

So what is the best way of going about this? 那么解决这个问题的最佳方法是什么? I tried several things but does not work well (tables, another list below with the underlines etc...) 我尝试了几种方法,但效果不佳(表格,下面带有下划线的其他列表等)

I would like it pure CSS and no javascript if possible...Which I believe it is 我希望它是纯CSS的,如果可能的话没有JavaScript的。。。我相信这是

Thank You 谢谢

ul#ul1 > li:hover{
    text-decoration:underline;
}

Use a bottom border to simulate an underline (see jsfiddle ): 使用底部边框模拟下划线(请参阅jsfiddle ):

#otherTable ul li:hover {
  border-bottom: solid red 0.2em;
}

http://jsfiddle.net/Tymek/2P8UL/ http://jsfiddle.net/Tymek/2P8UL/

HTML 的HTML

<div id="menu">
    <ul>
        <li><a href="#">Web Design</a></li>
        <li><a href="#">Graphic Design</a></li>
        <li><a href="#">Google Search Optimization</a></li>              
    </ul>
</div>​

CSS 的CSS

#menu ul,
#menu li,
#menu a {
    background: #111;
}    

ul#menu {
    list-style: none;
}

#menu li {
    display: block;
    float: left;
}

#menu a {
    display: block;
    margin: 0 0.5em;
    padding: 15px 0 7px;
    color: #ccc;
    text-decoration: none;
    text-transform: uppercase;
    font: 13px/18px Arial, Helvetica, sans-serif;
    font-weight: 300;    
}

#menu a:hover {
    color: #fff;
    padding-bottom: 4px;
    border-bottom: 3px solid #f00;
}

Key part: 关键部分:

#menu a {
    padding: 15px 0 7px;  
}

#menu a:hover {
    padding-bottom: 4px;
    border-bottom: 3px solid #f00;
}

Next time use firebug, or something to analize your example. 下次使用Firebug或其他方法分析您的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM