A long time ago, giraffes with long and short necks lived with each other. They like to eat leaves and twigs from trees.
As the shorter trees began to disappear, only the giraffes with long necks could reach the tall trees. Since the trees are hard to reach for other animals and short-necked giraffes, the long-necked giraffes have less competition.
The giraffes with longer necks have the advantage, which meant that the giraffes with the shorter necks began to disappear.
Overtime, the giraffes with long necks reproduce offspring that will also have long necks. These are the giraffes we see living today.