At night, cool air on mountaintops and hilltops sinks down into valleys because it's denser and heavier than than the warmer air at lower elevations. Valleys often contain creeks, streams, rivers and generally wetter ground. As the cooler air sinks into this warmer, more moist environment, the moist surface air cools and its moisture condenses into liquid water droplets (fog).
A key here is that cooler air can not hold onto as much moisture as warmer air. Warmer air at the valley floor holds onto invisible water vapor (water in its invisible gas state) until the invasion of cooler air at night forces that water vapor to turn into actual liquid water.
The other thing to note is that clouds and fog are basically the same thing; both are made of liquid water droplets.