Discrete ladders
Inside an isolated atom an electron can't sit at any old energy. It is only allowed to occupy a small set of levels — discrete rungs on a ladder. Quantum mechanics is what enforces that.
A photon can lift an electron from one rung to a higher rung only if its energy hν matches the gap between them. If the gap is wrong, the photon is ignored. If it is right, the photon is absorbed and the electron jumps. Later that electron can drop back, releasing a photon at the same energy.
From single atoms to crystals
Once you stack ~10²³ atoms together the levels merge into broad bands, with the empty band sitting on top of the full one separated by a forbidden gap. That story is the whole subject of semiconductors and band gaps.
But the basic absorption-and-emission rule survives the crowd: a material can only soak up colors of light that match an allowed transition between its electronic states.
- Electrons live on discrete energy rungs.
- A photon is absorbed only if its energy matches the gap.
- In a crystal those rungs widen into bands.