How did the Aztecs build a city over a lake?

The water and the chinampas they built were very fertile.  Chinampa comes from the Nahuatl chināmitl /tʃiˈnaːmitɬ/ and is a method by which small rectangular areas of fertile land grow on the shallow lake-beds of the Valley of Mexico.
Tenochtitlan, the capital of the Aztecs became one of the most important and influential cities of their time. They became the most powerful empire that dominated most of Mesoamerica.

Aztec Canals and Chinanmpas  Legend of Mexico City

Aztec Canals and Chinampas

 

The city grew so much that it came to have more than 2 000 inhabitants per square kilometer, and covered an estimated 8 to 13.5 km2 (3.1 to 5.2 sq mi).

More than 70 temples and buildings were constructed in the city over the lake of what is now the Zocalo of Mexico City.

 

They created long roads, avenues, and canals connecting the entire city and its surrounding areas. They had impressive temples and marketplaces, schools, parks, and homes.