WASHINGTON — When Mark Takano ran unsuccessfully for Congress twice in the early 1990s, his opponents tried to smear him as a “homosexual liberal” and a “nutzoid.” One of them even had pink fliers printed that asked, “A Congressman for Riverside … Or San Francisco?”

When he ran again last year, he won by almost 20 points. “Flash forward 18 years,” Mr. Takano said recently, “and the very macho building tradesmen are behind me. I’m getting pictures with them in their hard hats.”

For decades, the words “gay” and “Congress” were usually seen together only in stories of scandal and shame: an arrest after an illicit proposition in an airport bathroom, accusations of trawling for sex on a phone service. When Gerry E. Studds came out 30 years ago, the first congressman to do so, it was only after an affair with a 17-year-old Congressional page was revealed.