The sun produces white light, which is made up of light of all colors: red, orange, yellow, green, blue, indigo, violet. Light is a wave, and each of these colors corresponds to a different frequency, and therefore wavelength, of light. The colors in the rainbow spectrum are arranged according to their frequency... violet, indigo, and blue light have a higher frequency than red, orange, and yellow light.
When the white light from the sun shines through the earth's atmosphere, it collides with gas molecules. These molecules scatter the light.
The shorter the wavelength of light, the more it is scattered by the atmosphere. Because it has a shorter wavelength, blue light is scattered ten times more than red light.
Blue light also has a frequency that is closer to the resonant frequency of atoms than that of red light. If the electrons bound to air molecules are pushed, they will oscillate with a natural frequency that is even higher than the frequency of blue light. Blue light pushes on the electrons with a frequency that is closer to their natural resonant frequency than that of red light. This causes the blue light to be reradiated out in all directions, in a process called scattering. The red light that is not scattered continues on in its original direction. When you look up in the sky, the scattered blue light is the light that you see.
The setting sun looks reddish orange because when the sun is on the horizon, its light takes a longer path through the atmosphere to your eyes than when the sun is directly overhead. By the time the light of the setting sun reaches your eyes, most of the blue light has been scattered out. The light you finally see is reddish orange, the color of white light minus blue.
Violet light has an even shorter wavelength than blue light: It scatters even more than blue light does. So why isn't the sky violet? Because there is just not enough of it. The sun puts out much more blue light than violet light, so most of the scattered light in the sky is blue.
I hope that helped.
