HTML   发布时间:2022-04-14  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了html – 悬停边框位置大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在下面的代码中,我将底部边框设置为ul.将鼠标悬停在ul中的项目上时,我想在ul边框上准确显示底部边框或悬停项.我无法设置两个边框(ul和ul项)的位置,以便它们在悬停时相互依赖.

我尝试过使用绝对位置和线高,但无法取得多大成功.

这就是我想要的:

这是代码:

HTML

<div class="box">
    <ul>
        <li><a href="#">test 1</a></li>
        <li><a href="#">test 2</a></li>
    </ul>
</div>

CSS:

ul{
    list-style: none;
    padding: 0 0 10px;
    margin: 0;
    border-bottom: 5px solid green;
    overflow: hidden;
}

ul li{
    float: left;
    margin-left: 20px;
}

a{
    text-decoration: none;
    display: block;     
}

a:hover{
    border-bottom: 5px solid red;    
}

演示:
http://jsfiddle.net/nNvfy/

解决方法@H_607_21@
您想要定位ul和li – 将子li的底部偏移到边框的宽度,同时将其设置为透明,然后使用li:hover事件/选择器将broder颜色设置为红色.

Demo Fiddle

使用以下CSS:

ul {
    list-style: none;
    margin: 0;
    border-bottom: 5px solid green;
    position:relative;
    padding:0;
}
ul li {
    padding:10px 10px;
    margin-left: 20px;
    display:inline-block;
    position:relative;
    bottom:-5px; /* <-- offset bottom of li by border width so it overlaps ul green border */
    border-bottom: 5px solid transparent; /* add border,make transparent so it doesnt 'jump' on hover */
}
a {
    text-decoration: none;
    display: block;
}
li:hover {
    border-color:red; /* <-- use the li hover event (not a hover) to color the border */
}

大佬总结

以上是大佬教程为你收集整理的html – 悬停边框位置全部内容,希望文章能够帮你解决html – 悬停边框位置所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。