css - Why is transition on 'margin' and 'padding' laggy in webkit browsers? -
i tried apply css transition on margin
, padding
property.
i wanted make background visually larger on hover. increased padding , decreased margin accordingly on hover, text remain on current position.
here's code
.content { width: 600px; margin: auto; } a.btn { background-color: #5c9e42; color: #fff; text-decoration: none; font-size: 35px; border-radius: 5px; padding: 10px; text-shadow: 2px 2px 2px #696969; transition: 0.3s ease; } a.btn:hover { background-color: #23570e; padding: 20px; margin: -10px; }
<div class="content"> <p>lorem ipsum dolor sit amet, consectetur adipisicing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> <a href="#" class="btn">bello! how doing?</a> </div>
when run code can see, transition laggy , text gives jerk on hover.
however, happens in chrome, safari, opera , other webkit browsers. it's working fine in firefox , ie though.
p.s: making a.btn
s display
inline-block
reduced lag. issue?
a workaround apply transition on pseudo element background color , scale on hover. way, text remains "untransitioned" , won't wiggle :
css :
a.btn { position:relative; color: #fff; text-decoration: none; font-size: 35px; padding: 10px; text-shadow: 2px 2px 2px #696969; } a.btn:before{ content:''; position:absolute; top:0; left:0; border-radius: 5px; width:100%; height:100%; background-color: #5c9e42; z-index:-1; -webkit-transition: .3s ease; transition: .3s ease; } a.btn:hover:before { background-color: #23570e; -webkit-transform: scalex(1.1) scaley(1.2); -ms-transform: scalex(1.1) scaley(1.2); transform: scalex(1.1) scaley(1.2); }
you should include vendor prefixes transition
, transform
css properties, check caniuse more info.
Comments
Post a Comment