How do greenhouse gases trap heat?
To absorb infrared light, a stretching or bending vibration of the molecule must change the molecule's dipole moment. In $N_2$ and $O_2$ there is no dipole moment regardless of how you stretch the bond. On the other hand, O=C=O can change dipole moment by the C moving toward one O and away from the other O, or by bending with the C becoming a vertex of an obtuse angle. Water and methane molecules can also change dipole moment.