I attempted to use CSS transition effects on the margin
and padding
properties.
The goal was to create an illusion of a larger background upon hovering. To achieve this, I increased the padding and decreased the margin correspondingly on hover, ensuring that the text remained in its original position.
Below is the code snippet:
.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: all 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 do 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 are you doing?</a>
</div>
Upon testing the code, it became evident that the transition experienced some lag and the text appeared jerky when hovered over.
This issue seems to be specific to Chrome, Safari, Opera, and other webkit browsers as it works seamlessly in Firefox and IE browsers.
P.S: Changing the display
property of a.btn
to inline-block
alleviated the lag slightly. Any insights on what might be causing this problem?