开发者

How can we avoid the shake when we hover over an element and set its border?

How can we avoid the shake w开发者_如何学运维hen we hover over an element and set its border? Here is a sample of the code I wrote:

http://jsfiddle.net/s3N2h/

Is there a technique to avoid the shaking? Suppose I hover on File, the borders appears, but that line of text moves a little to the right due to the borders getting rendered. If we hover away it again shakes.

Is there any CSS way of avoiding such shakes?


The usual solution to this problem is to start off with a transparent border, then give the border a colour on hover.

I've updated your fiddle with this technique:

http://jsfiddle.net/s3N2h/1/

CSS and JavaScript:

#my_menu li {
    border: 1px solid transparent;
}

li.hover(function() {
    $(this).css('border-color', 'white #808080 #808080 white');
}, function() {
    $(this).css('border-color', 'transparent');
});​


Alternatively, when setting the border add a negative margin of the same size.


Sass

.image{
   border: 1px solid transparant;
   &:hover{
      border 1px solid red;
   }
}


Use -webkit-backface-visibility: hidden;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜