There are two phenomena at work here: the inverse-square law and extinction.
Picture a sphere centered on a star. At time $t_0$, a star emits $n$ photons, spread in random directions. At some time $t_1$, the photons are arranged in a sphere of radius $R_1$1. At some time $t_2$, the photons are arranged in a sphere of radius $R_2$, where $R_2>R_1$. This means that the photons are spread out more - and thus, the star appears dimmer at $R_2$ than it does at $R_1$. This is a consequence of the inverse-square law, because the surface area of a sphere is $4\pi r^2$.
Astronomical extinction is the absorption of photons by gas and dust spread throughout space. This can make observations difficult, because gas clouds and nebulae can easily block out most of a star's light.
In really extreme cases, a nebula or a related object will block out all the stars behind it. See, for example, Barnard 68, a molecular cloud:
Image courtesy of Wikipedia user Huntster under the Creative Commons Attribution 4.0 International license.
1 Specifically, at time $t_n$, $R_n=t_nc$, where $c$ is the speed of light.