Answer. Solar radiations reach up to the Earth and are absorbed by it. Then, this solar energy is (visible light) radiated as heat energy (infrared radiations) by the Earth. Keep in mind, wave length of visible light is shorter than that of infrared radiations radiated by the Earth. Due to this, visible light can pass through a medium from which infrared radiations cannot pass.
Carbon dioxide and water vapours present in the atmosphere are good infrared radiations absorber. Both of these gases allow the visible light to pass through it that reaches up to the Earth. But when Earth radiates the heat the form of infrared radiations, these gases absorb much of the outgoing infrared radiation that keeps the atmosphere warm. Thus presence of carbon dioxide and water vapours is responsible for maintaining the temperature of the atmosphere.