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.
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.
In addition to em and rem , a popular unit of choice for media queries is the good old pixel.
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) {...}
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With