WASHINGTON — The Trump administration’s losing streak in courts around the nation has in large part been a product of precedents established by conservative judges in the Obama era. It turns out that legal principles meant to curb executive overreach are indifferent to the president’s party.

Republican officials had great success under President Barack Obama in persuading judges to block or complicate his efforts to expand health care, shield immigrants from deportation and protect transgender students. Now Democratic officials are using the principles established in those cases to frustrate President Trump’s efforts to limit travel from predominantly Muslim countries and to punish so-called sanctuary cities.

Both sides have shown remarkable dexterity in their understanding of the law, abruptly switching positions on issues like whether states have standing to sue, whether individual federal judges may issue nationwide injunctions and whether a federal threat to withhold funds can amount to a constitutional violation.

Josh Blackman, a law professor at South Texas College of Law, said Democratic officials should strive for more consistency, even if only as a matter of self-interest. “Whatever California can do to resist immigration law,” Professor Blackman said, “Texas can do to resist environmental laws.”