President Trump acknowledges House Speaker Paul D. Ryan (R-Wis.) in the Rose Garden of the White House after the House of Representatives approved the American Health Care Act on Thursday. (Carlos Barria/Reuters)

How does this happen?

On Wednesday, the House passed a $1.2 trillion spending bill by a lopsided margin of 309 to 118. A majority of both Democrats and Republicans supported the measure, which sailed through the Senate.

House Minority Leader Nancy Pelosi (D-Calif.) and House Speaker Paul D. Ryan (R-Wis.) alike celebrated, and President Trump said of the spending bill: “This is what winning looks like!”

Yet the day after this bill passed the House, the chamber split down the middle as it passed the “Trumpcare” legislation repealing Obamacare. All 193 Democrats and 20 Republicans opposed the bill, which survived by the narrowest of margins, 217 to 213, and goes to the Senate, where it is so toxic that lawmakers there don’t even plan to take it up.

Pelosi bitterly told Republicans they would have the bill “tattooed on your forehead. You will glow in the dark on this one.” Democrats sang “Hey, hey, hey, goodbye” to Republicans on the House floor.

(Adriana Usero,Bastien Inzaurralde/The Washington Post)

How could the people’s representatives swing, in the space of 24 hours, from bipartisan congratulations to partisan recriminations? The difference was in Trump’s approach.

In the case of the spending bill, he acted as president of all Americans. He negotiated a compromise that thrilled nobody but satisfied the vast majority. In the case of the health-care bill, he catered to the most extreme elements of the Republican Party, the 30-or-so members of the House Freedom Caucus, winding up with a radical and slapdash bill that would, in the unlikely event it became law, be at direct odds with what Americans say they want.

Democrats crowed, a bit too much, about the spending agreement, which avoided funds for a border wall and a deportation force and avoided the defunding of sanctuary cities and Planned Parenthood. It didn’t embrace Trump’s proposed non-defense cuts. Pelosi bragged that “we handed President Trump a resounding defeat.”

That wasn’t entirely true. Trump got spending increases for defense and for border security, and more school choice in the form of the D.C. Scholarship Opportunity Program. Trump called the bill “a clear win for the American people.”

Unfortunately, that wasn’t the lesson Trump wound up taking away from the experience. An aide said Trump was angry that Democrats were “spiking the ball” by declaring victory. Trump tweeted that, when the current agreement expires, “Our country needs a good ‘shutdown’ in September to fix mess!”

This is exactly the wrong instinct, because such thinking created the Trumpcare abomination on Thursday. Republicans hypocritically jammed the bill through the House before members could read it or it could be given a price tag. They would eliminate popular protections for people with preexisting conditions, make older people pay more and give huge tax breaks to the wealthy. They would even eliminate protections against catastrophic costs for people on their employers’ plans.

Thus did Trump and congressional leaders cause House Republican lawmakers to walk the plank on health care, passing a bill that the Senate won’t even consider, just to satisfy 30 extremists from safe districts.

And it was unnecessary. For all the partisan fireworks, there is a health-care policy consensus out there for the taking if Trump chooses to. A Kaiser Family Foundation poll last month found a broad consensus on many health-care policies that crosses party lines: allowing the federal government to negotiate Medicare drug prices (92 percent), making it easier to bring generic drugs to market (87 percent) and requiring drug companies to disclose how they set prices (86 percent). The major elements of Obamacare, except for the individual mandate, are broadly popular. What Americans want, across party lines, is what Obamacare didn’t do well: making health care and prescriptions cheaper overall (including for the majority on employer plans).

In fact, on most issues, there is more consensus among Americans than most people realize. Research by the centrist group Third Way finds there is a consensus in favor of renewable energy (if it isn’t paired with rules cracking down on fossil fuels), citizenship for illegal immigrants (if paired with crackdowns on border security and illegal hiring), American leadership abroad (if it doesn’t mean boots on the ground) and universal background checks on gun sales (if there aren’t gun bans).

The problem is the consensus on these and many other issues breaks down when it is filtered through the lens of party. Once parties take sides, Americans take cues from leaders and shift their views to get in line.

If Trump, who only recently became Republican, wants to win until we’re tired of winning, there’s an obvious path to consensus. Alternatively, he and the members of the Freedom Caucus can celebrate the virtues of partisan polarity and ideological purity — in a very small room.

Twitter: @Milbank

Read more from Dana Milbank’s archive, follow him on Twitter or subscribe to his updates on Facebook.