I have the following HTML:
Hover:
-
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'} );
讨论(0)
-
You could add to the padding if you subtract from the border and vice versa.
讨论(0)
-
decrease the margin with the same amount of pixels you increase the border width with
讨论(0)
-
Decrease the width by two times the border increase ..
$('.Size').hover(
function() {
var width = parseInt($(this).css('width'));
$(this).css('borderWidth', '5px').css({width:width-8});
},
function() {
var width = parseInt($(this).css('width'));
$(this).css('borderWidth', '1px').css({width:width+8});
})
have a look at http://jsfiddle.net/rBrZL/
讨论(0)
-
You can use "outline" instead of border is browser support is OK with you.
讨论(0)
-
Yes, add a position: relative; left: -5px;
to position it correctly.
讨论(0)