Remember that we can draw resonance structures to get a feel for charge distribution within a molecule. If we do this for the two bases, we find that the charges make for an attractive hydrogen bond.