I have a weakness for pictures. So here is one
function http://pages.bangor.ac.uk/%7Emas010/compactopen2.jpg (source)
The above shows a function $f: \mathbb R \to \mathbb R$, a compact set $C$, and an open set $U$. The condition $f(C) \subseteq U$ is that the graph of $f$ passes through the shaded part shown in the picture.