Giraffes are believed to have short necks but there was a chance in neck length variations. Some giraffes have a little longer compared to the average length. The main source of nutrition for giraffes is tree leaves. Maybe there was an environmental change that occurred that there was a limited source of leaves and as a result, there were more giraffes than trees; therefore, there is a struggle for existence.
In this event, variation, fitness differences, and inheritance (3 ingredients of natural selection) must occur for the species to survive. Longer necked giraffes are more likely to reach the leaves of the trees and have a higher chance of survival and reproduction; thus, they have greater fitness. This trait (long necks) was passed on to the offspring and eventually, all giraffes have long necks.
The allele frequency of the population of giraffes eventually changes to favor the trait that will give the species a higher chance of survival in their environment.