To clarify what happened for the unawares:
After the 1860s the Republican Party rose to power as the party who freed the slaves and (to a lesser extent) supported reconstruction.
Later, both parties had a lot more centrists and it was a time of great social progress around the world after the fall of right-wing fascist Nazi Germany in 1946, but there were also fears about the USSR and the Cold War becoming hot.
During the Civil Rights Movement which sought equal rights for its citizens and protections for segregated racial minorities to live and work freely a bipartisan bill (mostly Republicans of the time) passed congress called the Civil Rights Act of 1964 and later the Voting Rights Act of 1965, and to a lesser extent the Food Stamps program and several other welfare bills, but credit for it was mostly given to then Democrat President Lyndon B. Johnson aka "El Big Johnson".
There were a lot of reasons for this, perhaps racist conservatives are just easily misinformed or perhaps Republicans thought to muddy the waters of the discourse of their opponents, but more civil rights activists started to shift to the Democrats side. Still, it was a time of little polarization and great centrism until over time political polarization made politicians vote along party lines more and more every year. You could still see widespread examples of Republicans being pro-union in the 70s and 80s, and Democrats still supporting bad crime bills into the early 2000s.
Ronald Reagan being the man to gut regulations and cut taxes for corporations from under 90% to under 20% was a huge instigator of the Republican Party's shift towards conservatism.
So thats why Republicans then supported nearly opposite stances from Republicans now. Both Sides voting base hardly shifted at all, it's just the banner they chose did.