Republicans and Democrats switched idealogies for some reason down the road.
It was around the civil rights era. Republicans were generally more liberal than Democrats in those days, but in the 1964 presidential election, Barry Goldwater won the Republican primary. He was staunchly against the civil rights act, while Lyndon B. Johnson was more open to it.
Republicans also started successfully using the southern strategy to appeal to the racist voting block that always voted for the Southern Democrats in the south.
Lyndon B. Johnson won the election and went on the sign the civil rights act of 1964 as well as the voting rights act of 1965. This along with the Republican southern strategy tactics pushed the Southern Democrat voting block to vote for Republicans and pushed the black community to start voting for Democrats.