简体   繁体   English

元素边界正在继续悬停

[英]element border is moving on hover

I want right border to always be static. 我希望右边界始终是静态的。 At this moment, when I hover li element border-right is moving down 5px because of the border-top of 5px on hover. 此时,当我悬停li元素border-right因为悬停时5px的border-top而向下移动5px。

HTML HTML

<nav>
   <ul>
     <li><a href="link1">link1</a></li>
     <li><a href="link2">link2</a></li>
     <li><a href="link3">link3</a></li>             
     <li><a href="link4">link4</a></li>
   </ul>
  </nav>

CSS CSS

    nav li a {
    border-right: 1px solid #cdcdcd;
    }
    nav ul li:first-child a:hover {
        border-top:5px solid #d1e751;
    }
    nav ul li:nth-child(2) a:hover {
        border-top: 5px solid #F06B50;
    }
    nav ul li:nth-child(3) a:hover {
        border-top: 5px solid #eee;
    }
    nav ul li:last-child(4) a:hover {
        border-top: 5px solid #a8def4;
    }

http://jsfiddle.net/Xfy6P/ http://jsfiddle.net/Xfy6P/

add this at the bottom and it will fix it ^^, by adding padding-bottom on the hover it will compesate the extra pixels that the border top will add, its like 18 - 5 = 13 and the border right will remain the same 在底部添加它,它将修复它^^,通过在悬停上添加填充底部它将补充边框顶部将添加的额外像素,它像18 - 5 = 13并且边框右边将保持不变

nav ul li a:hover{
    padding-bottom:13px;
}

Set Top border with background color of container like 设置顶部边框与容器的背景颜色像

nav li a {
    border-right: 1px solid #cdcdcd;
    border-top: 5px solid [background-color];
    }

just added one property in your CSS code. 刚刚在CSS代码中添加了一个属性。

nav li a {
    border-top:5px solid transparent; /* using the transparent border to achieve the result*/
    border-right: 1px solid #cdcdcd;
}

try by adding following code 尝试添加以下代码

nav ul li a{
        padding-top:23px;
    }
     nav ul li a:hover{
        padding-top:18px;
     }

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

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