This fact is explained by the fact that the energy levels that electrons may be in are quantized, or vary by a specific amount. When electrons go from one energy level to another, the difference in those energy level is a specific value, and not a range of values. If they are transitioning upwards towards a higher energy, they will absorb the photons corresponding to the wavelength of light which has the specific amount of energy they need to ascend, resulting in dark lines.
Similarly, when the electrons transition from higher to lower energy, the same specific amount of energy is released and the emission spectrum shows lines in the places where the absorption spectrum was dark.