The Earth's crust, or lithosphere (hard outer surface) is made up of "tectonic plates", or large plates. There are about 7 major plates and many smaller plates, around 100 km thick, which sit upon a lower soft layer (the asthenosphere). When these plates move against each other along plate boundaries (where two plates meet) or along faults (a rift), an earthquake occurs. This may be through a variety of movements: sideways, up and down or apart. This causes anything upon the upper surface, above the earthquake, to also shift, whether they be buildings, roads, bridges, railways, etc.
What you actually feel when you feel the shaking of an earthquake are the seismic waves.An earthquake describes when the earth moves the ground under your feet. It can slide it from side to side or move it a few feet in one direction. It can lift it up in one place and make it sink in another. The results of this are quite visible in and near Anchorage, Alaska. One street in that town shows where an earthquake make the ground fell. Driving south, dead trees stick up out of a lake where the ground fell below sea level. Earthquakes are caused when faults or cracks in the earth's shell suddenly slip past each other. When they jerk, they move a lot of land with them. That makes the earth tremble. Sometimes it damages buildings.
No one can predict earthquake. If there is an earthquake, one should pray for safety.