i think the answer you’re looking for is hydrogen bonding or dipole dipole interactions. These interactions happen between molecules that are polar. Meaning their atoms don’t share their electrons equally and one’s more electronegative than the other one.
Hope this helps:)