Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Unused CSS Stages Media Queries Print Style Sheets

Aditya ojha
Aditya ojha
4,510 Points

If a device has a pixel-ratio of 2, then 1 CSS pixel is displayed as physical pixel(s) on screen.

what will be the answer and why

4 Answers

Benjamin Harrison
Benjamin Harrison
10,958 Points

It is displayed as 4 physical pixels. This is because the ration of 2 is being applied across the X and Y axis.

Meaning that 1 css pixel with a ratio of 2 is being displayed as 2 horizontal pixels and 2 vertical pixels for a total of 4 pixels.

To make a square :)

Abubakar Usman
Abubakar Usman
6,463 Points

Simply multiply the CSS pixel with the device-pixel-ratio to get the number of pixels to be displayed on screen. For example, a device with pixel-ratio of 1, 1 CSS pixel will be 1px on screen. Likewise, a device with pixel-ratio of 2, 1 CSS pixel will be 2px on screen. In the same way, a device with pixel-ratio of 3, 2 CSS pixels will be 6px on screen.

Why? It is a simple ratio between physical resolution and actual screen size (logical resolution) i.e., device-pixel-ratio = physical resolution/actual screen size.

Benjamin Harrison If you are considering both width and height, I guess the best way to present the screen resolution is in the form: width x height, i.e., 2px x 2px, instead of 4px.

pixel-ratio x css-pixel = number of physical pixels

ex. 2(pixel-ratio) x 1(css-pixel) = 2(number of physical pixels)

Gabi Udrescu
Gabi Udrescu
11,539 Points

I would take a lucky guess and say 2. according to wikipedia... http://en.wikipedia.org/wiki/Pixel_aspect_ratio (see the images in the first screen on the right)