For a trait to evolve, firstly, there has to be genetic variation among individuals, which will lead to differences in phenotype and cause differences in fitness in a particular environment. These differences in fitness (which are a consequence of the different phenotypes) have to be heritable in order to be passed on to the next generations and continue the evolutionary process. Finally, a selective pressure is required, usually a change in the environment, to act upon the population, favouring individuals with a particular trait which will increase their chances to live longer, reproduce and pass on their adaptive traits. In conclusion, there has to be variation among the population, these differences must have a genetic basis and there has to be a selective pressure acting upon them to drive evolution.
Example: In a population of feral dogs, some have longer legs than others. These dogs depend on hunting rabbits to survive. Dogs with longer legs are faster and therefore have a higher hunting success, this will increase their chances of survival and reproduction (increased fitness) compared to dogs with shorter legs. Since the long leg trait is genetic (and therefore heritable), it will be passed to the next generation and the next generation will have a higher percentage of long legged dogs compared to the previous one. (1-Variation in leg length; 2-Leg length is a genetic trait; 3-Selective pressure of depending on hunting rabbits to survive)