gpt4 book ai didi

html - 悬停边界位置

转载 作者:太空狗 更新时间:2023-10-29 13:57:21 26 4
gpt4 key购买 nike

在下面的代码中,我设置了 ul 的底部边框。将鼠标悬停在 ul 中的元素上时,我想显示底部边框或恰好在 ul 边框上的悬停元素。我无法设置两个边框(ulul 项)的位置,以便它们在悬停时相互重叠。

我试过使用绝对位置和行高,但没有取得多大成功。

这就是我想要的:

enter image description here

代码如下:

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/

最佳答案

你想定位你的 ulli - 用你的边框宽度偏移子 li 的底部,同时设置它为 transparent 然后使用 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 - 悬停边界位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24800803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com