The more salt that is added to the water, the higher the egg or other less dense object floats. The density comes from the amount of molecules present in the water. Saltwater has more molecules than fresh water. Thus, varying amounts of salt can be added to water to have the egg float in different spots, such as the middle of the glass. Another factor to consider is temperature. Cool water is significantly more dense than warm water.
The rule of less dense objects floating in denser water applies to larger scenarios as well. It is easier for a person to stay afloat in the ocean than in a swimming pool. Ships can easily float because they spread their density out on the surface and because some ships have air pockets, which is much less dense than water.
This concept even applies to scuba diving. Divers must make sure that in saltier water they wear more weight so that they can move and actually sink. Some have to double their body weight to adequately dive.Learn more about Dairy & Eggs