Javascript - Changing border-width without moving surrounding elements.

前端 未结 8 1371
萌比男神i
萌比男神i 2021-02-14 09:43

I have the following HTML:

Hover:


8条回答
  •  野的像风
    2021-02-14 10:11

    When I do this and I want that same +border -movement result, I like to do this:

    function() { 
        $(this).css('borderWidth', '7px');
        $(this).css('margin', '-7px');
    });
    

    The negative margin brings everything back in.

    You can also condense the styles into an object and pass them in one .css() call:

    $(this).css( {borderWidth: '7px', margin: '-7px'} );
    

提交回复
热议问题