Bob the Builder
Bob the Builder

Reputation: 543

Increase button size not text size

I have a button that I am trying to make sightly bigger on hover by increasing the padding but I want the text to stay exactly the same size and position as at present its moving down, how is this possible? Thank you in advance.

HTML

<button type="submit">
          Checkout
        </button>

CSS

button{
position: relative;
width: auto;
background-color: #eb4f47;
border-radius: 0;
color: #fff;
border: 2px solid #eb4f47;
font-size: 0.7rem;
font-weight: 800;
letter-spacing: 2px;
text-decoration: none;
text-align: center;
text-transform: uppercase;
padding: 10px 20px;
line-height: 2.2;
vertical-align: middle;
cursor: pointer;
transition: outline 0.1s linear;
box-sizing: border-box;
margin-top: 20px;
}

JQUERY

//Animate Checkout button
$("button").mouseenter(function(){
           console.log('enter');
           $(this).css("padding", "12px 23px");
        }).mouseleave(function(){
              console.log('leave');
              $(this).css("padding", "11px 24px");
        });

Upvotes: 0

Views: 190

Answers (5)

Bob the Builder
Bob the Builder

Reputation: 543

Sackey's suggestion worked a treat -

//Animate Checkout button
$("button").mouseenter(function(){
           console.log('enter');
           $(this).css("outline", "2px solid #eb4f47");
        }).mouseleave(function(){
              console.log('leave');
              $(this).css("outline", "none");
        });

Much appreciated all the posts!

Upvotes: 0

Jagdish yadav
Jagdish yadav

Reputation: 1

I did it this way. You can further css if you want

#checkout{
  font-size: 15px;
  position: absolute;
  padding: 5px 5px 5px 5px;
  transition: 0.30s;
}
#checkout:hover{
  padding: 20px 20px 20px 20px;
  transition: 0.30s;
}
<button type="submit" id="checkout">
  Checkout
</button>

Upvotes: 0

Ivananutrition
Ivananutrition

Reputation: 56

Try to use hover pseudo class and transform scaleX() scaleY()

button:hover {
transform: scaleX(1.4) scaleY(1.6);
}

look here https://jsfiddle.net/tygm0jez/7/

Upvotes: 0

Atul Rajput
Atul Rajput

Reputation: 4178

You can do this just by CSS, no need of jQuery. This is what I understood by your requirements, pleas let me know if you need something else

button{
position: relative;
width: auto;
background-color: #eb4f47;
border-radius: 0;
color: #fff;
border: 2px solid #eb4f47;
font-size: 0.7rem;
font-weight: 800;
letter-spacing: 2px;
text-decoration: none;
text-align: center;
text-transform: uppercase;
padding: 10px 20px;
line-height: 2.2;
vertical-align: middle;
cursor: pointer;
transition: all 0.2s linear;
box-sizing: border-box;
margin-top: 20px;
}

button:hover {
padding: 10px 24px 12px 20px;
}
<button type="submit">
          Checkout
        </button>

Upvotes: 1

If you want the "text" to stay and the same "place" when you hover try using:

$("button").mouseenter(function() {
  $(this).css("padding", "10px 24px 14px 20px");
}).mouseleave(function() {
  $(this).css("padding", "10px 20px");
});

Demo

$("button").mouseenter(function() {
  $(this).css("padding", "10px 24px 14px 20px");
}).mouseleave(function() {
  $(this).css("padding", "10px 20px");
});
button {
  position: relative;
  width: auto;
  background-color: #eb4f47;
  border-radius: 0;
  color: #fff;
  border: 2px solid #eb4f47;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-decoration: none;
  text-align: center;
  text-transform: uppercase;
  padding: 10px 20px;
  line-height: 2.2;
  vertical-align: middle;
  cursor: pointer;
  transition: outline 0.1s linear;
  box-sizing: border-box;
  margin-top: 20px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="submit">
          Checkout
        </button>

Upvotes: 1

Related Questions