The Dude The Dude - 25 days ago 7
CSS Question

How to make table cell animation extend on hover

I have a problem with css animation.

In my case I have table with 2 languages. On language hover, I want the table to extend to full width of the table... current code works only on first language... If I hover over second element the cell only strutters, it doesnt extend to left direction.

Heres a snippet



.locale-wrapper {
width: 80px;
height: 40px;
}

.locale-text {
vertical-align: middle;
text-align: center;
border: 1px solid black;
font-size: 16px;
width: 50%;
-webkit-transition: all .5s;
-moz-transition: all .5s;
-o-transition: all .5s;
transition: all .5s;
transition-timing-function: ease-in-out;
-moz-transition-timing-function: ease-in-out;
-webkit-transition-timing-function: ease-in-out;
-o-transition-timing-function: ease-in-out;
}

.locale-text:hover {
width: 100%;
}

<table class="locale-wrapper">
<tr>
<td class="locale-text">SL</td>
<td class="locale-text">EN</td>
</tr>
</table>




Answer

If you fix the size of your table to 80pxand your tdwidth to 50% you know that there's only two cell then use 40px instead of 50%it doesn't work on the second cause the first try to keep his 50% of width. And fix your :hoverwidth in px too.

Working example :

.locale-wrapper {
    width: 80px;
    height: 40px;    
}

td.locale-text{
  vertical-align: middle;
  text-align: center;
  border: 1px solid black;
  font-size: 16px;
  width: 40px;
  -webkit-transition: all .5s;
  -moz-transition: all .5s;
  -o-transition: all .5s;
  transition: all .5s;
  transition-timing-function: ease-in-out;
  -moz-transition-timing-function: ease-in-out;
  -webkit-transition-timing-function: ease-in-out;
  -o-transition-timing-function: ease-in-out;  
}

td.locale-text:hover {
  width: 80px;
}
<table class="locale-wrapper">
  <tr>
    <td class="locale-text">SL</td>
    <td class="locale-text">EN</td>
  </tr>
</table>