- min-
- max-
- >=
- > NEW
- <
@media (min-width: 600px) @media (max-width: 600px) @media (width >= 600px) @media (width > 600px) @media (width < 600px) @media (width: 600px)
<link media="screen" ...
<style media="screen"> @import "myCSS.css"; ...
@import url(myCSS.css) screen;
@media screen {}
<?xml-stylesheet media="screen" ...
@media screen and (max-width: 600px) { #presentation { background: red; } } @media screen and (orientation: portrait) { #presentation { background: yellow; }
@media screen and (orientation: landscape) { a[href^="mailto:"]:before { content: url(icons/email.gif); } }
<link rel='stylesheet' media='screen and (min-width: 320px) and (max-width: 480px)'
href='css/smartphone.css' />
@media screen and (max-width: 480px){ selector { /* small screen */ property: value; } } @media screen and (orientation: landscape) { selector { /* landscape properties */ property: value; } } @media screen and (min-device-pixel-ratio: 1.5) { selector { /* properties for higher resolution screens */ property: value; } }
width
height
aspect-ratio
orientation
resolution
scan
grid
update
none | slow | fast
(Media Queries 4)overflow-block
none | scroll | optional-paged | paged
(Media Queries 4)overflow-inline
color
@media (min-color: 1)
means it's a color devicecolor-gamut
srgb | p3 | rec2020
(Media Queries 4)color-index
@media (color-index) { … }
or
@media (color-index >= 1) { … }
or @media (min-color-index: 1)
matches color index devicesdisplay-mode
display
member (Defined in the Manifest Spec)monochrome
inverted-colors
pointer
none | coarse | fine
(Media Queries 4)hover
any-pointer
any-hover
light-level
scripting
device-width
device-height
device-aspect-ratio
Note: 0 is invalid. O is not equal to 0dpi, 0dpcm, or 0dppx.
Safari v. Everyone Else
-webkit-min-device-pixel-ratio: 2 min-resolution: 2dppx min-resolution: 192dpi
dppx fallback
min-resolution: 192dpi
@media (-webkit-min-device-pixel-ratio: 2), /* Safari */ (min-resolution: 192dpi) /* Everyone else */ {}
const dpi = window.devicePixelRatio;
"only" leaves out older browsers
media="only print and (color)"
"and" - both parts must be true
media="only screen and (orientation: portrait)"
"not" - if untrue
media="not screen and (color)"
Comma separates selectors - any part can be true
media="print, screen and (min-width: 480px)"
@media (min-width: 600px) @media (max-width: 600px) @media (width >= 600px) @media (width > 600px) @media (width < 600px) @media (width: 600px)
@supports
@supports (display: flex){ /* rules for browsers supporting unprefixed flex box */ }
Don't use
@media screen and (transform-3d) { .transforms {} }
@media screen and (min-width: 320px) and (max-width: 500px){ @-ms-viewport { width: device-width;} }
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
device-width
(width of screen)device-height
(height of screen)@viewport { width: device-width; zoom: 0.5; }
@media screen and (max-width:400px) { @-ms-viewport { width:320px; // or device-width;} }
If <meta> is set to disable zoom, there is no delay on onClick events.
If <meta> is set to disable zoom, you're a jerk!
Tap Highlight Color
-webkit-tap-highlight-color: #bada55;
Prevent Select & Hold dialogue
-webkit-user-select: none;
Prevent Images Dialog
-webkit-touch-callout: none;
Prevent accidental OS popups (panning)
-ms-touch-action: none;
column-count: 1; column-width: 10em; column-rule: 1px solid #bbb; column-gap: 2em;
Adipisicing rump nostrud exercitation turkey, bresaola deserunt ullamco beef ribs pork loin ball tip pig pork belly nisi. Cillum sunt officia deserunt, beef aliqua ham ut t-bone sed ut consequat shoulder. Nostrud excepteur biltong non, fatback salami incididunt beef cupidatat occaecat.
Reprehenderit ham hock labore tri-tip chuck, excepteur ut. Meatball sint enim beef ribs, mollit laborum flank commodo fatback pariatur tail rump eiusmod spare ribs dolore. Ut minim qui, tongue eu short ribs pancetta excepteur incididunt culpa consequat pastrami magna chuck. Flank sunt sint, occaecat ut adipisicing labore turkey laboris in magna.
Chicken bacon meatloaf minim meatball salami sunt spare ribs.
Bacon sed tail, pork loin pariatur meatloaf hamburger exercitation corned beef shank ex esse sirloin qui beef ribs. Consectetur anim corned beef, cupidatat ex enim tempor. Pariatur consectetur ad, enim ut quis consequat aliquip exercitation jowl tenderloin ham dolore.
Fugiat excepteur aliqua, cow dolor swine shoulder elit tri-tip shankle. Irure consectetur cow labore, cupidatat exercitation ea jerky ham officia dolore tongue eu aliqua. Ham hock irure beef ribs non, flank sausage eiusmod ham short loin nostrud.
Prefix -webkit & -moz. Supported since IE 10, O 11.1, all webkit, all FF