1. For solar-system objects and relatively nearby stars, you can use the trigonometric parallax. What is parallax? For a quick demonstration, stretch out your arm, hold out your thumb upwards and close one eye. Then switch to the other eye and look at the thumb again. Even though your thumb is still, it looks like it's moving. This is because your eyes are a certain distance apart. Schematically, it looks like this:

Distance to star = (Earth-Sun distance) / (parallax)
2. Parallax works for close-by stars, but what about really far away ones that don't seem to be moving at all? How can we get the distances to them? There are many other methods we can use and here's one of them: Main-Sequence fitting.
To explain how this method works, I'll need to introduce you to an old friend, the Hetrtzsprung-Russel diagram, shown below:

What this diagram shows is the evolution of the lives of stars. Based on many, many measurements, this is plot of the absolute brightness (also called luminosity or magnitude) of stars relative to their surface temperatures. I also need to explain the difference between absolute and apparent brightness, so let's do that first.
The light coming from a car's headlights when the car is far away will of course appear to be dimmer than if the car was closer. In other words, if you take two car headlights that are equally bright, but one is only half the distance away of the other, it will appear to be brighter. This is called apparent brightness and it is used to describe how bright a star appears to us on Earth. On the other hand, absolute birghtness is used to describe how bright the star really is.
The temperature of the star is directly related to it's colour, so Red stars are cooler than Blue stars, which have surface temperatures of tens of thousands of degrees. Astronomers measure the colour of stars by taking observations at different wavelengths (using different filters) and taking the ratio of the brightnesses. It turns out that this can be measured with great accuracy, so from that we can derive the temperature of the star, and using the information in the diagram above, we can find out the absolute brightness. Comparing this absolute brightness with the apparent brightness gives us a measure of the distance to the star. This method actually works for stars thousands of light years away!
This is by no means an exhaustive list of the methods used to determine distances to stars. To find out about some other methods, check here.