Right off note that 'the stars & bars' isn't the red 'confederate' flag with the X extending from corner to corner.
The actual 'stars & bars' looks a lot like the US flag except with 2 red stripes & one white stripe (i.e. the bars) and about a dozen stars in the blue field symbolizing the states that seceded and the 2 or 3 that weren't able to b/c Northern troops occupied them to keep them in the Union. Because the flag looked so much like the US flag from a distance, it had a tendency to cause dangerous confusion on the battlefield. So the Confederate government decided to change the flag.
For the actual military units in the field, Confederate units were issued a perfectly square red flag with blue X on it. This was the 'battle flag' of the Confederacy. When the Confederate government decided to change their national flag, they took the battle flag design & slapped it on the upper left corner of a white rectangular flag. Unfortunately when the wind didn't blow this white flag looked like a surrender flag. So the Confederates added a single red bar going from top to bottom on the end opposite of the little battle flag design on the corner.
As to what the 'battle flag' means, it was the flag issued to Confederate units that were fighting NOT for slavery but for "states' rights", i.e. being able to decide what's good for your state's population instead of being told by D.C. This fight still goes on today, in a sense, whenever folks argue that they "don't want Washington meddling in our local business", etc.
Anyway, after the Civil War the Federals occupied the South to insure blacks got their newly granted rights. Unfortunately, the Federals used heavy-handed methods to do so. Looking at their burnt & devastated country, left to fend for themselves without government help but watching ex-slaves getting lots of help, several southerners began to rebel against all this. They wore white sheets to represent the ghosts of Confederate dead, flew the old "battle flag", & called themselves the Ku Klux Klan. Though they originally wanted to ensure justice for the defeated southerners, many of them turned to terror to the get the job done.
The flag's meaning began to change from one of 'states rights' to organized terror. Sadly, heritage groups like The United Daughters of the Confederacy did nothing to stop the Klan from mis-using the flag. Nor did they intervene when Southern states began to use the flag as part of their state flags to show they would not enforce civil rights laws for blacks. As a result the flag came to be known as a symbol of hate.
Nowadays, while there ARE white southerners who still use the flag as symbols of hate many whites are reclaiming the flag as a symbol of heritage. Thus why you'll occasionally see bumper stickers with the battle flag on it and the motto "Heritage, Not Hate". Still, after about 100 years of misuse by the Klan, its not surprising most Americans associate the flag with racism.