Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix dancing button?

Consider the following button style:

body {
  padding: 1rem;
}

button {
  background: blue;
  color: #fff;
  padding: 1rem;
}

button:hover {
  transform: translateY(-3px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .18);
}
<button>kinda shaky</button>  

When I pointed at border, then the button start dancing!!

enter image description here

How to fix dancing button?

like image 807
mitsuruog Avatar asked Jan 29 '23 05:01

mitsuruog


1 Answers

Easy fix is to use a wrapper and display it as inline-block:

body {
  padding: 1rem;
}

span {
  display: inline-block; /* "inline-flex" is ok too */
}

button {
  background: blue;
  color: #fff;
  padding: 1rem;
}

span:hover > button {
  transform: translateY(-3px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .18);
}
<span><button>kinda shaky</button></span>
like image 121
VXp Avatar answered Jan 31 '23 07:01

VXp