html - 如何在具有边框图像的整个 <li> 上建立链接?

标签 html css menu hyperlink navigation

我想要一些有效的代码,没有 <a><li></li></a>
问题来了:
http://jsfiddle.net/BquwS/

我也必须在这里添加代码,因为我不能问 jsfiddle-link-only 问题,所以这是 html:

<nav id="menu">
<ul>
<li><a href="#">Blog</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Gallery</a></li>
</ul>
</nav>

这是我遇到问题的 css。

#menu {
    width: 180px;
    padding: 0 10px 10px 10px;
    float:left;
    text-align:center;
    font-size:20px;
    font-weight:bold;
    line-height:15px;
}
#menu ul{
    list-style-type:none;
}
#menu li{
    height:15px;
    background-color:#404468;
    margin:20px 0 20px 0;
    /*border-image*/
    border: 1px solid transparent;
    border-image:url("http://users.atw.hu/darksoul90/egyeb/border.png") 45 45 45 45 stretch stretch;
    border-width:17px 17px 17px 17px;
    -moz-border-image:url("http://users.atw.hu/darksoul90/egyeb/border.png") 45 45 45 45 stretch stretch;
    -webkit-border-image:url("http://users.atw.hu/darksoul90/egyeb/border.png") 45 45 45 45 stretch stretch;
    border-image-outset: 10px;
}
#menu li:nth-child(odd){

    -ms-transform:rotate(1deg); 
    -webkit-transform:rotate(1deg);
    transform:rotate(1deg);
}
#menu li:nth-child(even){
    -ms-transform:rotate(-1deg); 
    -webkit-transform:rotate(-1deg);
    transform:rotate(-1deg);
}
#menu a {
    display:block;
    height:100%;
    width:100%;
    color:#b7c4d8;
    text-decoration:none;
}
#menu a:hover {
    color:#Ff0;
}

最佳答案

由于粗边框,链接的可点击区域很窄。您可以扩展链接的可点击区域,但这需要绝对定位。

http://jsfiddle.net/89Rv8/7/

http://jsfiddle.net/89Rv8/7/show

#menu li {
  position: relative;
}
#menu a {
  color: #B7C4D8;
  display: block;
  left: -17px;
  line-height: 30px;
  min-height: 33px;
  position: absolute;
  text-decoration: none;
  top: -17px;
  width: 141px;
}

关于html - 如何在具有边框图像的整个 <li> 上建立链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22546815/

相关文章:

php - 我的 HTML 表单使用 PHP 和 MySQL 无法正常工作

javascript - 如何将现有 ul 的所有 li 添加到另一个基于其 css 类的 ul 的底部

css - 出现溢出:auto element to auto scroll

css流体布局问题

用于 ListView 项的 Android 工具栏上下文菜单

view - 如何向 Eclipse RCP 中的窗口菜单添加 View ?

javascript - qTip 在每个之后更改特定工具提示的文本

javascript - Jquery 函数也应该与其他元素一起工作

c# - 如何在单击游戏对象时创建菜单? (统一)

javascript - 未定义 Photoswipe UI 默认值