Million years ago when invertebrates die they get buried inside the sea bed and sand gets deposited on it forming rock by time. Later on after some years dinosaurs die and also get fossilized in the form of rock above the fossil of invertebrate. After some more years other animal die and get fossilized above the fossil of dinosaurs. This process goes on and form a layer by layer of fossils.