css链接元素在悬停时跳转 [英] css link element jumps on hover

查看:22
本文介绍了css链接元素在悬停时跳转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在悬停时在链接周围放置边框,并且样式适用于它,但是当我悬停在它上面时它会跳转(元素跳转)...我该怎么办?代码:

I am trying to put a border around a link on hover, and the style applies to it, but it jumps (the element jumps) when i hover over it... what can I do? code:

  .navigation li:hover {
   border: 1px solid #ccc;
 }

推荐答案

你'跳跃'是由边框的 1px 高度引起的,导致你的 li 移动

You 'jump' is caused by the 1px height of the border, that make your li move

你可能会使用

 .navigation li:hover {
   border-color: #ccc;
 }

 .navigation li {
   border: 1px solid #<parentBackgroundColor/transparent>;
 }

相反.这样,边框从一开始就在这里,所以在悬停时不会跳转,而且它是不可见的,因为它与父容器的颜色相同或透明.

instead. This way, the border is here from the beginning, so no jump on hovering, and it's invisible, since it's the same color of the parent container or transparent.

这篇关于css链接元素在悬停时跳转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆