tags:

views:

34

answers:

2

I have an animated rating bar which changes width when you mouse over it.

I tried to write a explanation of the problem, but I think it is far easier to have a look at the link.

Essentially I am having trouble centering a div as the children div's change size when the mouse is hovered over them. I have tried animating the width of the parent div at the same time but with no success.

http://degreeshowcase.com/test3.html

+1  A: 

just checked your codes : do this

#ratebar {
font-size:14px;
font-weight:bold;
margin:50px auto;
width:auto;/*change this*/
}

now to position div wrap this div with some other div

Praveen Prasad
Using `width: auto` sets the width to 100%. Wrapping in another div but setting `width: auto` just moves the problem up to its parent.
ClarkeyBoy
A: 

An alternative to Praveen Prasads method:

I notice you are setting each child div to width of 20px, but at any time only one can be more than that (26px). The width you have set on the parent div is 210px. Each child div, apart from the first one, has a border of 1px.

So the maximum total width of all the child divs is worked out as follows:

9 * 20 = 180 //standard div width
1 * 26 = 26  //hovered div width
9 * 1  = 9   //border
Total: 215
215 is more than 210 so the last one drops down.

Minimum total width of all child divs is worked out as follows:

10 * 20 = 200 //standard div width
9 * 1   = 9   //border
Total: 209
209 is less than 210 so the last one stays on the same line as the rest.

The solution: try setting the width of the parent div to 215px or more. This should solve the problem.

ClarkeyBoy
the div's width is variable!
elektronikLexikon
hmm I just tried this out using Googles Inspect Element thing, and turns out that even at 250px the last child div moves to the next line. This only happens if you move the mouse over all of them really quickly. It works great if you use width of 300px. Oh and using width: auto sets the width to 100% - tried it with a grey background and you can see quite clearly that it does this.
ClarkeyBoy