A method of preparing a three-dimensional composite material includes the following steps: preparing polystyrene by soap-free emulsion polymerizing, obtaining polystyrene opal by a vertical deposition method, synthesizing MoP IO (molybdenum phosphide inverse opal), and compounding with quantum points CdS, so as to obtain a novel inorganic composite material, namely cadmium sulfide quantum dot-compounded MoP IO. The preparation method has the advantages that the MoP IO is prepared first, and the MoP IO is of a three-dimensional cyclic pore structure and has the photonic band gap feature, so that the MoP IO has better catalysis effect in light catalysis in comparison with that of common porous material; the MoP IO is compounded with the cadmium sulfide quantum dots, so that the light absorbing ability is enhanced, and the composite material capable of absorbing the visible light is obtained.