By Sharon Ogunleye

LAGOS (Reuters) - A floating school built to withstand storms and floods at a lagoon in Nigeria's commercial capital Lagos and educate children from a nearby slum has collapsed only seven months after its official opening.

The aid-funded Makoko Floating School offered free education to children from nearby huts on stilts. Most of their parents fish for a living and, like most of the megacity's 23 million residents, lack a reliable electricity and water supply.

Heavy rains brought down the pyramid-shaped wooden school, built on a platform held afloat by hundreds of plastic barrels, on Tuesday. None of its nearly 50 pupils were in the building when it collapsed, officials said.

Classes had already been moved to another location in late March after heavy downpours at the start of the rainy season began to affect classes.

    "It is not only the floating school that collapsed. It collapsed many houses surrounding the floating school," said David Shemede, Makoko resident and brother to the school's director.

Building collapses are a common problem in the West African nation, sometimes due to the use of poor materials and weak enforcement of regulations. At least 30 people died when a building collapsed in an upmarket Lagos district in March.

The school was built to adapt to changing water levels and withstand the storms and floods that lash Lagos in the four-month-long rainy season.

Its Nigerian architect Kunle Adeyemi said in a statement that the Makoko community was considering upgrading the structure and rebuilding an improved version of the school.

Makoko was established as a fishing village hundreds of years ago but climate change and rapid urbanization are now threatening its way of life.

The school was officially opened in November 2015 after being in use for more than a year beforehand. It took three years to build and catered to children coming from the only English-speaking school in the area.

Pupils traveled to the school by canoe.

(Writing by Alexis Akwagyiram; Editing by Ulf Laessing and Tom Heneghan)