This is because these elements have a strong tendency to lose or gain electrons, respectively, in order to achieve a stable electron configuration.
For example, sodium (Na) from Group 1 will readily react with chlorine (Cl) from Group 7 to form sodium chloride (NaCl), a stable ionic compound.