This question has probably been ask before and since I'm not from the US I don't know if the answer is too obvious. It seems rather curious to me however that the parties seem to have completely flip form their 19th century ideologies. These can be seen for example in the nowadays republican party and voter defending the use of the confederate flag or the stablishment of confederate statues, whilst the creator of said party would become mortified to that idea.
As noted, there are a number of posts dealing with this in the FAQ, but I will try to add some detail that I believe could expand on the discussion. I advise reading all of those posts as well to get a general consensus view on the topic.
For one thing, we should clarify up front that for most of American history, the "two parties" (we will here deal with the Democratic and Republican Parties post-1860, but obviously there were a variety of smaller parties and previous political entities within the system) were not strongly ideological in a traditional left-right spectrum, and certainly not in a way that would be recognizable or coherent to a post-1970s American who grew up with "liberal" and "conservative" as relatively stable terms. In the early 1900s for instance, both parties had "conservative" and "Progressive" wings, and varied on any number of issues. Both Theodore Roosevelt (R) and Woodrow Wilson (D) could be accurately described as "Progressives" in that era because of their views on business, labor rights, the role of government, and so on. But Wilson would not be considered "progressive" by the standards of today with his extremely retrograde views and policy on race. [1] Likewise, former Populists like Tom Watson of Georgia began their political careers as agriculturally-minded, reform-spirited champions of a "grand coalition" between white and black farmers eventually gave up on this vision when it reached a political dead end, and switched instead to hardcore white supremacy, though they never gave up their support for the white working class, especially poor rural whites. [2]
Second, we should absolutely not delude ourselves about the appetite for civil rights legislation and policies friendly to African-Americans among Northerners, once the region with staunchest Republican support, and later Democratic support. Though most Northerners detested slavery for one reason or another (I wrote more about this here), most also still took white supremacy for granted, and were partly enthusiastic for reform in the South because they believed it would keep blacks confined to the South rather than push them to the North and West. [3] Likewise, in the 20th century, it is easy to imagine the South as a Jim Crow sea of racist darkness, and the North as a region of comparative racial harmony, but that was not quite the case. Though Northern States did not have the same system of de jure segregation given the shorthand of "Jim Crow," a variety of de facto systems of segregation and racial animus were prevalent throughout Northern States. Racism has always been an American problem, not just a Southern one. Nonetheless, many African-Americans moved to the North and West in waves during Reconstruction, the first part of the twentieth century and after the First World War, partly for economic opportunity, and partly as refugees escaping political violence in the South. Lest I paint too negative a picture, many black residents in Northern cities including Chicago, Detroit, and New York did substantially better than their rural Southern brethren. [4]
So let's deal more concretely with the subject of political realignment. When people mention this, the most notable feature is that the North moves from being predominantly Republican to predominantly Democratic, and vice versa for the South. This is more complicated than a "liberal vs conservative" split, but there's some validity to that interpretation. The most important era to discuss in this context is the New Deal, particularly the election of 1936, when FDR won a landslide victory and became the first Democrat to win a majority of the African-American vote. It's important to note here that this was due in large part to the efforts of organized labor, and the Democratic Party's decision to court labor as a principal constituency in the industrial North. Though there was a fairly established history of Northern Democrats being the "working man's party" and Republicans being the "business man's party" (that much has been true since the 1860s), at least in perception, FDR and New Deal Democrats were far more open about support for unions, codifying federal protections for them under the Wagner Act in 1935. [5] Labor in turn became the political base of a "grand coalition" of white and black workers that proved instrumental in the success of Democratic politicians going forward. This was an unstable coalition, however, since the South largely remained under one-party rule of more conservative, Jim Crow Democrats, who frequently undercut New Deal programs deemed too favorable to black Americans. Through their control of key committees in Congress, they effectively disenfranchised many African-Americans from receiving Social Security benefits by exempting sectors like agriculture and domestic work, and steered through explicitly racist policy in the creation of the FHA. [6] The center could not hold, and the Democratic Party could not possibly have satisfied the many constituencies that had led to their complete dominance in the elections of 1936.
The next moment we should examine is 1948, covered in a fair amount of detail in some of the FAQ posts. Truman, running as a fairly explicit successor to FDR (though not to the satisfaction of dove New Dealers like Henry Wallace), provoked a challenge from Southern conservatives embodied in Strom Thurmond. The conservatives disdained Truman's decision to desegregate the armed forces in July of that year, and "Dixiecrats" (conservative Southern Democrats) walked out en masse in response to Hubert Humphey's speech declaring, " The time has arrived in America for the Democratic Party to get out of the shadow of states' rights and to walk forthrightly into the bright sunshine of human rights." Dixiecrats, running Thurmond as their candidate, won four States in the Deep South in the election of 1948, a clear sign the Democratic coalition was fracturing. I will detail this in a reply to this post, as this is getting pretty long.
[1] TK Nugent, Progressivism: A Very Short Introduction
[2] Charles Postel, The Populist Vision and Leon Litwack, Trouble in Mind
[3] Eric Foner, Reconstruction and Charles M. Payne, "The Whole US is Southern!"
[4] Litwack, above, and Jacquelyn Dowd Hall, "The Long Civil Rights Movement"
[5] David M. Kennedy, Freedom from Fear
[6] Richard Rothstein, The Color of Law
Hi -- this does get asked here fairly frequently. You may be interested in this section of our FAQ.