Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using cm in responsive media queries?

I'm using centimeter in my CSS media queries to make my template responsive, while these days we have smartphones with very high resolutions that makes pixel filters difficult. my question is that why all websites don't use CM which makes responsive much more easy and functional? is there anything going to be missed by using cm that I don't know?

Edit: I'm using min-**device**-width as a media query.

like image 550
Payam Shakibafar Avatar asked Nov 30 '13 08:11

Payam Shakibafar


People also ask

Should I use max width or min-width in media queries?

If you are designing your website for smaller devices first then set your initial breakpoints with min-width, whereas, if you are designing for larger devices first then use max-width. This post discusses min-width, and max-width media features in detail along with relevant examples.

What unit should I use for media queries?

In addition to em and rem , a popular unit of choice for media queries is the good old pixel.

How do you use min-width and maximum width together in media query?

If you want to include both min and max width for responsiveness in the browser, then you can use the following: @media (min-width: 768px) and (max-width: 992px){...} @media (min-width: 480px) and (max-width: 767px) {...}

How do you add height and width in media query?

Use a comma to specify two (or more) different rules: @media screen and (max-width: 995px), screen and (max-height: 700px) { ... } Commas are used to combine multiple media queries into a single rule. Each query in a comma-separated list is treated separately from the others.


2 Answers

I'd been also keen on using physical units for CSS measurements, as it makes a lot of sense, specifically for designing reading experience of long form content on all types of devices. But the problem with this approach is that 1 CSS cm/in is absolutely not the same as 1 cm/in in the real world. Just try making a box with width and height of 1cm, and then measure the rendering in different browsers, screens and devices. You may be unhappily surprised.

The fundamental problem is that all (? well most) devices render physical units as (surprise) an equation of 1in = 96px (or 1cm = ~37.8px). So if you define your units or media queries in cm, that virtually means you define them in ~37.8 pixels ratio, which in most cases certainly is not what you want to.


like image 92
Artem Marchuk Avatar answered Sep 22 '22 09:09

Artem Marchuk


There's really no benefit in using cm over px.

One of the official CSS3 Candidate Recommendations defines these absolute lengths:

unit    definition
‘cm’    centimeters
‘mm’    millimeters
‘in’    inches; 1in is equal to 2.54cm
‘px’    pixels; 1px is equal to 1/96th of 1in
‘pt’    points; 1pt is equal to 1/72nd of 1in
‘pc’    picas; 1pc is equal to 12pt

Therefore 1cm is roughly equal to 37.80px. If a device's screen width measures 10cm, then in pixels this is roughly 378px.

Note here how I've said "device width". Media queries support 2 different width and height queries: min-width and min-height are based on the screen's resolution; min-device-width and min-device-height are based on the size of the screen.

You can refer to the official Media Queries documentation for further information.

like image 23
James Donnelly Avatar answered Sep 20 '22 09:09

James Donnelly