.
I'm pulling this from James McPherson, The Battle Cry of Freedom. In short, there were three main factors.
The South picked a pretty awful time to rebel from an economic standpoint. The years preceding the Civil War had been unusually productive, creating a cotton surplus in both the North and England. These surpluses lasted long enough for both parties to secure alternate sources of cotton.
While the Deep South that was the heart of the cotton industry seceded as a block, loyalty to the Union was stronger in the Upper South. While cotton cultivation wasn't as common in Maryland, Delaware, Kentucky, and Missouri as it was in the Deep South, those states could still provide cotton (and tobacco) to the Union.
As federal forces advanced into the Confederacy, they were able to capture rebel-held stockpiles of cotton and buy from Southerners willing to sell to Unionist merchants. A particularly notable example was when the Union navy captured New Orleans intact, with the warehouses full of cotton on the city's docks unharmed.