Dynamic navigation?

so i am working on some buttons that are arranged in a vertical group. When you click on one it expands pushing the others away, and collapsing when clicked again bringing them back together.

I thinking it would be easiest to make each button how i want it, then have some code that keeps each button x pixels away from each other…make sense?

how would i go about the code to make this happen?