So basically – warm air can hold a lot more water molecules than cold air. If you have warm water at the surface, then it is going to stay pretty warm for quite a while even if cold air comes in. The air right above the surface is warm and can hold a lot of water vapor but as it rises it cools until relative humidity hits 100% and you have fog. If you have a colder surface it’s just the opposite. You can also have fog when a warm front moves over top of a cold front and it starts to rain. The rain can evaporate before it gets to the ground and then since it’s in the colder air near the ground it will reach 100% relative humidity faster.
You see it a lot at night because bodies of water maintain their temperature quite well and will stay warmer than the cold night air. The water particles also can’t actually stick together in the air. They clump up in the air around solid particulates like dust, sea foam, pollutants, and so on. So the concentration of those in the air might effect how densely or whether fog forms.
Latest Answers