Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

button width css transition doesn't work

I'm having a issue with a transition css property in a button tag.

When I hover the button I supposed it will go smoothly to width:auto, but it jump directly.

This is the code, what did I miss?

<button>Hello</button>

button {
   padding: 10px;
   width: 30px;
   overflow:hidden;
   transition: width 400ms ease-in-out;
   -webkit-transition: width 400ms ease-in-out;
   -moz-transition: width 400ms ease-in-out;
}

button:hover {
   width: auto;
}
like image 685
Alejandro Garcia Anglada Avatar asked Nov 19 '25 07:11

Alejandro Garcia Anglada


1 Answers

max-width is your friend

Demo

button {
   padding: 10px;
   width: auto;
   max-width: 30px;
   overflow:hidden;
   transition: max-width 400ms ease-in-out;
   -webkit-transition: max-width 400ms ease-in-out;
   -moz-transition: max-width 400ms ease-in-out;
}

button:hover {
   max-width: 100%;
}
like image 175
Popnoodles Avatar answered Nov 20 '25 19:11

Popnoodles