floats break
But display:inline-block
with white-space:nowrap
does not.
jquery:
var dur = 300;//set vars
$('.box').hover(function(){//on in
$(this).stop().animate({ width: '40%' },dur)//animate
.siblings('.box').stop().animate({ width: '15%' },dur);//animate sibs
}, function(){//on out
$('.box').stop().animate({ width: '20%' },dur);//animate all
});
css:
.grd_box {
position:absolute;
width:50%;
height:50%;
background-color:red;
padding:5px;
overflow:hidden;
white-space:nowrap;/*stop line breaks*/
font-size:0/*remove spacing on children*/
}
.box {
position:relative;
height:100%;
width:20%;
display:inline-block;/*show inline*/
font-size:16px;/*set font size back*/
vertical-align:top;/*align to top*/
white-space:normal/*return whitespace*/
}
html:
<div class="grd_box">
<div class="box a"></div>
<div class="box b"></div>
<div class="box c"></div>
<div class="box d"></div>
<div class="box e"></div>
</div>
made a fiddle: http://jsfiddle.net/filever10/eV3mH/
or if you don't want to worry about the number of elements
jquery
//set vars
var dur = 300,//duration
box = $('.box'),//elements
bl = box.length,//no of elements
bi = 100/bl,//initial size
bo = bi*2,//large size
bs = (100-bo)/(bl-1);//small size
box.css({width: bi+'%'})//set width
.hover(function(){//on in
$(this).stop().animate({ width: bo+'%' },dur)//animate
.siblings().stop().animate({ width: bs+'%' },dur);//animate sibs
}, function(){//on out
box.stop().animate({ width: bi+'%' },dur);//animate all
});
and remove width:20%;
on .box
in the css.
like this: http://jsfiddle.net/filever10/h4HLR/