First, we can only animate things that have explicit numeric values, such as width, left, or margin. We cannot animate things like alignment (which actually use the same margin property, but implicitly, never mind). Therefore, if we know the width of the inserted div, just add it to our container.
1) Let the very center of the container and add a transition to it
.container { width: 102px; margin: auto; transition: width 0.5s; }
2) Then increase the width when add div
$(".container").width($(".container").width() + 102);
3) But wait! If we add a div to a container too narrow, it will be added from the bottom to the right. Therefore, we need another container installed for the appropriate width before.
See the final example in JSFiddle .
BTW, remove all line breaks and tabs from your code when you use the inline block, because this will cause spaces between your blocks.
source share