The sun, Earth and the moon are aligned, but because the moon's orbit is not exactly in the same plane as Earth's orbit around the sun, they rarely form a perfect line. When they do, we have a lunar eclipse as Earth's shadow crosses the moon's face.
Gravity is the force by which a planet or other body draws objects toward its center. The force of gravity keeps all of the planets in orbit around the sun.