html - 无法在第一个和最后一个 child 上进行异常形状的悬停

标签 html css

查看 JSfiddle 显示我在做什么:http://jsfiddle.net/Amp3rsand/FPj3s/1/

HTML:

<ul id="navigation">
    <li><a href="#">BLAH</a></li>
    <li><a href="#">MORE <br /> BLAH</a></li>
    <li><a href="#">STILL <br /> MORE</a></li>
    <li><a href="#">YADDA <br /> YADDA</a></li>
    <li><a href="#">ETC ETC <br /> ETC ETC</a></li>
    <li><a href="#">FINISH</a></li>
</ul>

CSS:

body {
    font-size: 12px;}
}
#navigation {
    width: 600px;
    height: 50px;
    position: absolute;
    left: 20px;
    top: 25px;
}

#navigation li {
    list-style-type:none;
    width: 94px;
    height: 40px;
    display: block;
    float: left;
    margin: 0 5px 0 0;
    text-align: center;
    font-weight: bold;
    background: lightgrey;
}

#navigation li:first-child {
    border-top: 40px solid lightgrey;
    border-left: 25px solid transparent;
    height: 0;
    width: 70px;
    background: none;
}

#navigation li:first-child a {
    position: relative;
    top: -35px;
    right: 0px
}

#navigation li:last-child {
    border-top: 40px solid lightgrey;
    border-right: 25px solid transparent;
    height: 0;
    width: 70px;
    background: none;
}

#navigation li:last-child a {
    position: relative;
    top: -35px;
    left: 5px;
}
#navigation li:last-child a:hover {
    top: -35px;
    left: 5px;
}

#navigation li a {
    display: block;
    height: 40px;
    text-decoration: none;
    color:#000;
}

#navigation li a:hover {
    background: grey;
}

浅灰色形状是我希望悬停的样子。只有第一个和最后一个 child 需要看起来不同,但我不确定如何在悬停时弄乱边框而不破坏布局。由于边界恶作剧,我不得不移动第一个和最后一个“a”元素,现在我陷入困境。 你有什么建议?


编辑: 我刚刚意识到我可以这样做来改变悬停位的形状,但链接位置仍然造成麻烦

#navigation li:last-child a:hover {
    border-top: 40px solid grey;
    border-right: 25px solid transparent;
    height: 0;
    width: 70px;
    background: none;
}

See it live here on JS Fiddle

最佳答案

您要更改的属性属于 <li>元素因此以列表项悬停状态为目标并更改背景和边框颜色

#navigation li:hover {
    background: grey;
}

#navigation li:first-child:hover,
#navigation li:last-child:hover{
    background: none;
    border-top-color: grey;
}

<强> Updated fiddle

关于html - 无法在第一个和最后一个 child 上进行异常形状的悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18179984/

相关文章:

javascript - 如何在 jquery 中单击时更改元素的 zIndex?

html - 悬停时纯 css3 表格行覆盖

html - CSS 边框在 div 外溢出

javascript - 使用 jQuery 将文本附加到文本区域的末尾

javascript - 使用 JQUERY 选择的 cb 列表的复选框过滤

html - 动态加载页面内容及其CSS - 如何防止因为尚未加载CSS而跳转?

javascript - 如何根据滚动选择菜单项?

html - 防止 2 个 div 元素之间的分页符

javascript - 如何在 javascript 中调整 Image 对象的大小并继续使用修改后的对象

html - 防止渲染阻塞 CSS