Actually, I once read an old textbook that did talk about the giraffe neck being long because it needed to reach high leaves.
That's almost certainly wrong. Giraffes use the necks primarily for weapons in mating struggles, and secondarily for observation. They mostly browse lower branches.
Most likely, the neck is the result of allometry; as giraffoids get progressively larger in absolute terms, their necks get relatively longer.
At some point, they were long enough to be adapted to a new use.
But natural selection seems to have little to do with it at first.
(details on request)