Think of the P-channel (top) and N-channel (bottom) MOSFET transistors as a voltage divider. The two resistances are controlled by the input voltage. When the input is high P-channel has large tesistance and N-channel has small resistance, so the output is pulled down. Similarly, the output is pulled up when when the input is low.