The answer lies in electronegativity. When a proton attracts an electron, the electron doesn’t magically suck out the charge of the proton. The proton’s charge is still distributed in all directions. The reason why 1 proton on average can attract only 1 electron is because electrons push each other out.
Now let’s first take H – it has 1 proton, which attracts 1 electron. If another electron jumps in, only 1 electron stays in the end. Then He – it has 2 protons, so it attracts electrons even more. So even though electrons are fighting for the place, the nucleus charge is enough to hold them.
It gets interesting with Li. It should have 3 electrons. But 1st shell can take only 2 electrons, so the 3d electron must go to the 2nd shell, which is further away. In such cases, the inner shell of electrons has a much greater effect on the outer electron; this is called electron screening, not to mention that the further you are from the nucleus – the weaker the attraction. So even though Li has more protons than He, it’s too weak to hold electrons on the 2nd shell so that some other atom will take the electron away, and Li will be ionized and become Li++ with only 2 electrons.
How strongly an atom wants new electrons is called electronegativity. It increases to the right of the periodic table because the nucleus gets larger and larger and can hold on more and more electrons. In the last columns, atoms want electrons so much that they can mug other atoms with weaker electronegativity.
But then the row of the table finishes and the new row starts. At this point, the previous shell is filled, and a new shell starts and the electron screening kicks in again.
Electronegativity is the reason why Na & Cl can’t form a molecule (covalent bond) – Cl (strong electronegativity) takes Na’s (weak electronegativity) electron, and both become ions: Cl− and Na+. In the end, they form an ionic bond instead.