Water is a liquid, which is the second form of matter between solids and gasses. The molecules that make up the structure of a liquid are spaced out farther than those of a solid, allowing it to move fluidly, but are closer together than those of gasses, allowing them to keep a semi-specific form. In other words, liquid molecules cannot space themselves out from each other near-indefinitely like those of gasses, but they can move farther apart from each other than those of solids. Because of this, liquids will generally expand to fill whatever container they are inside of, and as such will take on the shape of said container. To answer your initial question, water (technically) floats and sinks because, depending on the container it's in, the water molecules are essentially stacked on top of each other. The water on top is technically "floating" above the water beneath it, which technically "sank" beneath what is on top of it.