This effect is called responsive web design which uses media queries to target specific device sizes.
You can learn more about how to use and work with media queries by watching these intro videos:
https://www.youtube.com/watch?v=TPmb7xHCLO0
https://www.youtube.com/watch?v=F_fhyXUH_To
Also, here is a great article that can save you a lot of time and frustration:
http://css-tricks.com/snippets/css/media-queries-for-standard-devices/