SlideShare une entreprise Scribd logo
1  sur  16
Viewport and Media Queries

    The Complete Idiot's Guide
           last updated on 4/4/2011
Viewport and Media Queries

Tiny little pixels can be big headaches (if you read a pixel is not a pixel
is not a pixel, you know what I am talking about). Everybody talks about
viewport and pixels, few knows what they are about, even fewer can
explain them in an idiot and complete way.

Nevermind the pixels, here comes the Complete Idiot's Guide to
Viewport and Media Queries!!!
viewport
1. viewport - width
You can define the width of viewport. If you don’t use width=device-width, on iOS your
page stretches over the full available width of the layout viewport, which is 980px, if you
use width=device-width, your page will fit into screen size of 320px. So in boilerplate, we
use:
<meta name="viewport" content="width=device-width">
1. viewport - width
Question:
Should I always use width=device-width?

Answer:
If your site is a fluid layout desktop design, using it is generally better when viewing the
site on mobile devices.
If your site is a fixed layout desktop design, it’s up to you, doesn’t matter.
If your site is a mobile specific design, just use it.
2. viewport - target-densitydpi
Before talking about this property, let's briefly talk about pixel. The easiest way to explain
this is to think about your desktop, on the same monitor if you adjust resolution, your
desktop icons look smaller when you use high resolution, and bigger when you use low
resolution.

Android introduced target-densitydpi. When you set target-
densitydpi=device-dpi, with the same physical phone size, images/text will look
smaller on a high resolution device, and bigger on a low resolution device.
2. viewport - target-densitydpi
Question:
So what’s the problem with target-densitydpi=device-dpi? We are fine with it
when we adjust our monitor right?

Answer:
The problem is that a high resolution device can be twice as high as a low resolution one,
with the same physical device size, such big difference can make your pixel related
everything shrink into half the size.
2. viewport - target-densitydpi
Question:
Is there a iPhone equivalent of target-densitydpi=device-dpi

Answer:
Not really. In iPhone, you can only specify width=device-width. Regardless of whether it's
iPhone 3 or 4, the device-width is always 320px in portrait mode.


Question:
How about Window Phone?

Answer:
Windows phone also uses 320px as device-width in portrait mode, which is why it's good
to make Android behave the same way as iPhone and Windows Phone. The consistency
will make it much easier when styling.
3. viewport - scaling
On most smartphones, default scaling may occur that will 'zoom' your pages on mobile
browser. To prevent user scaling, you can use initial-scale=1.0. So now, below
is the full version of our 'viewport boilerplate':

<meta name="viewport" content="width=device-width, initial-scale=1.0">
Media Queries
4. CSS Media Queries - max/min-device-width
If you want to have a CSS style that only smartphones will pick up, use:
@media only screen and (min-device-width : 320px) and (max-device-width : 569px) {...}
                   Example of HTC Desire HD, it has a width of 533 in landscape mode
5. CSS Media Queries - max/min-width
max-width and min-width are updated when you rotate the screen, your max-width in
portrait mode become max-height in landscape mode

@media only screen and (min-width : 480px) { .box { width:200px; height:200px;
background:yellow; } }
@media only screen and (max-width : 320px) { .box {width:200px; height:200px;
background:red; } }
below screen will be rendered when the above style applied:
5. CSS Media Queries - max/min-width
Question:
Is max/min-width the same as max/min-device-width?

Answer:
If you set width=device-width, then max/min-width is the same as max/min-device-width
inportrait mode, and different when in landscape mode.

In short, the difference is max/min-width will update when you rotate the screen, whereas,
max/min-device-width won't.
6. CSS Media Queries - device-pixel-ratio
device-pixel-ratio could help you know the resolution of the device screen, iPhone 4 and
certain other smartphones have pixel ration equal or higher than 1.5, so if you want to
target high resolution devices, you can use the media query below:

@media only     screen and (-webkit-min-device-pixel-ratio : 1.5),
       only     screen and (-o-min-device-pixel-ratio: 3/2),
       only     screen and (min-device-pixel-ratio : 1.5) {
  .imagebox     {background:(url:"images/high/demo.jpg");}
}

Be cautious!!! when you are using it in the above way, the image will be downloaded even if the page
doesn't fit the rule above.
7. CSS Media Queries - orientation
iPad introduced 'orientation' to help with detecting orientation change, below is how you
can specify landscape and portrait style

/* iPads (landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width :
1024px) and (orientation : landscape) {
  /* Styles */
}
/* iPads (portrait) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width :
1024px) and (orientation : portrait) {
  /* Styles */
}
Thank you




    Brought to you by Mobile Boilerplate http://html5boilerplate.com/mobile/

                     Shi Chuan, Paul Irish, Divya Manian

Contenu connexe

Tendances

Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!
Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!
Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!FITC
 
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...Sencha
 
Goodbye, Flatland! An introduction to React VR and what it means for web dev...
Goodbye, Flatland! An introduction to React VR  and what it means for web dev...Goodbye, Flatland! An introduction to React VR  and what it means for web dev...
Goodbye, Flatland! An introduction to React VR and what it means for web dev...GeilDanke
 
Responsive Web Design e a Ubiquidade da Web
Responsive Web Design e a Ubiquidade da WebResponsive Web Design e a Ubiquidade da Web
Responsive Web Design e a Ubiquidade da WebEduardo Shiota Yasuda
 
Game Development Using HTML 5
Game Development Using HTML 5Game Development Using HTML 5
Game Development Using HTML 5osa_ora
 
Understanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile BrowsersUnderstanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile BrowsersAriya Hidayat
 
HTML5 and CSS3 Shizzle
HTML5 and CSS3 ShizzleHTML5 and CSS3 Shizzle
HTML5 and CSS3 ShizzleChris Mills
 
WebVR - MobileTechCon Berlin 2016
WebVR - MobileTechCon Berlin 2016WebVR - MobileTechCon Berlin 2016
WebVR - MobileTechCon Berlin 2016Carsten Sandtner
 

Tendances (10)

Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!
Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!
Bringing Virtual Reality to the Web: VR, WebGL and CSS – Together At Last!
 
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
 
Goodbye, Flatland! An introduction to React VR and what it means for web dev...
Goodbye, Flatland! An introduction to React VR  and what it means for web dev...Goodbye, Flatland! An introduction to React VR  and what it means for web dev...
Goodbye, Flatland! An introduction to React VR and what it means for web dev...
 
Responsive Web Design e a Ubiquidade da Web
Responsive Web Design e a Ubiquidade da WebResponsive Web Design e a Ubiquidade da Web
Responsive Web Design e a Ubiquidade da Web
 
Game Development Using HTML 5
Game Development Using HTML 5Game Development Using HTML 5
Game Development Using HTML 5
 
Understanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile BrowsersUnderstanding Hardware Acceleration on Mobile Browsers
Understanding Hardware Acceleration on Mobile Browsers
 
WebVR - JAX 2016
WebVR -  JAX 2016WebVR -  JAX 2016
WebVR - JAX 2016
 
Images and PWA in magento
Images and PWA in magentoImages and PWA in magento
Images and PWA in magento
 
HTML5 and CSS3 Shizzle
HTML5 and CSS3 ShizzleHTML5 and CSS3 Shizzle
HTML5 and CSS3 Shizzle
 
WebVR - MobileTechCon Berlin 2016
WebVR - MobileTechCon Berlin 2016WebVR - MobileTechCon Berlin 2016
WebVR - MobileTechCon Berlin 2016
 

Similaire à Idiot's Guide to viewport and pixel

Designing for mobile
Designing for mobileDesigning for mobile
Designing for mobileDee Sadler
 
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive WebsitesJoe Seifi
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignJulia Vi
 
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake OilCSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake Oiljameswillweb
 
Responsive website design
Responsive website designResponsive website design
Responsive website designsvaithiyalingam
 
How to Project-Manage and Implement a Responsive Website
How to Project-Manage and Implement a Responsive WebsiteHow to Project-Manage and Implement a Responsive Website
How to Project-Manage and Implement a Responsive WebsiteJj Jurgens
 
Responsive web design
Responsive web designResponsive web design
Responsive web designBen MacNeill
 
Supporting multi screen in android
Supporting multi screen in androidSupporting multi screen in android
Supporting multi screen in androidrffffffff007
 
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...Patrick Lauke
 
The specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktopThe specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktopbetabeers
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web DesignTung Dang
 
Presentación WPmallorca PalmaActiva responsive design
Presentación WPmallorca PalmaActiva responsive designPresentación WPmallorca PalmaActiva responsive design
Presentación WPmallorca PalmaActiva responsive designWPMallorca
 
Modern Frontend Technologies (BEM, Retina)
Modern Frontend Technologies (BEM, Retina)Modern Frontend Technologies (BEM, Retina)
Modern Frontend Technologies (BEM, Retina)Nascenia IT
 
Designing Android apps for multiple screens
Designing Android apps for multiple screensDesigning Android apps for multiple screens
Designing Android apps for multiple screensAbhijeet Dutta
 
Responsive Web Designs
Responsive Web DesignsResponsive Web Designs
Responsive Web DesignsNusrat Khanom
 
WDEV118 Media Queries
WDEV118 Media QueriesWDEV118 Media Queries
WDEV118 Media QueriesGene Babon
 
Responsive website building approach. Olga Smolyankina and Kate Kalashnikova
Responsive website building approach. Olga Smolyankina and Kate KalashnikovaResponsive website building approach. Olga Smolyankina and Kate Kalashnikova
Responsive website building approach. Olga Smolyankina and Kate KalashnikovaADCI Solutions
 

Similaire à Idiot's Guide to viewport and pixel (20)

Designing for mobile
Designing for mobileDesigning for mobile
Designing for mobile
 
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive Websites
 
divide and qonquer
divide and qonquerdivide and qonquer
divide and qonquer
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake OilCSS3 Media Queries: Mobile Elixir or CSS Snake Oil
CSS3 Media Queries: Mobile Elixir or CSS Snake Oil
 
Responsive website design
Responsive website designResponsive website design
Responsive website design
 
How to Project-Manage and Implement a Responsive Website
How to Project-Manage and Implement a Responsive WebsiteHow to Project-Manage and Implement a Responsive Website
How to Project-Manage and Implement a Responsive Website
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 
Supporting multi screen in android
Supporting multi screen in androidSupporting multi screen in android
Supporting multi screen in android
 
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
Adapt and respond - mobile-friendly layouts beyond the desktop - standards>ne...
 
The specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktopThe specs behind the sex, mobile-friendly layout beyond the desktop
The specs behind the sex, mobile-friendly layout beyond the desktop
 
Responsive Web Design
Responsive Web DesignResponsive Web Design
Responsive Web Design
 
Presentación WPmallorca PalmaActiva responsive design
Presentación WPmallorca PalmaActiva responsive designPresentación WPmallorca PalmaActiva responsive design
Presentación WPmallorca PalmaActiva responsive design
 
Modern Frontend Technologies (BEM, Retina)
Modern Frontend Technologies (BEM, Retina)Modern Frontend Technologies (BEM, Retina)
Modern Frontend Technologies (BEM, Retina)
 
Designing Android apps for multiple screens
Designing Android apps for multiple screensDesigning Android apps for multiple screens
Designing Android apps for multiple screens
 
Responsive Web Designs
Responsive Web DesignsResponsive Web Designs
Responsive Web Designs
 
WDEV118 Media Queries
WDEV118 Media QueriesWDEV118 Media Queries
WDEV118 Media Queries
 
Responsive website building approach. Olga Smolyankina and Kate Kalashnikova
Responsive website building approach. Olga Smolyankina and Kate KalashnikovaResponsive website building approach. Olga Smolyankina and Kate Kalashnikova
Responsive website building approach. Olga Smolyankina and Kate Kalashnikova
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Dernier (20)

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

Idiot's Guide to viewport and pixel

  • 1. Viewport and Media Queries The Complete Idiot's Guide last updated on 4/4/2011
  • 2. Viewport and Media Queries Tiny little pixels can be big headaches (if you read a pixel is not a pixel is not a pixel, you know what I am talking about). Everybody talks about viewport and pixels, few knows what they are about, even fewer can explain them in an idiot and complete way. Nevermind the pixels, here comes the Complete Idiot's Guide to Viewport and Media Queries!!!
  • 4. 1. viewport - width You can define the width of viewport. If you don’t use width=device-width, on iOS your page stretches over the full available width of the layout viewport, which is 980px, if you use width=device-width, your page will fit into screen size of 320px. So in boilerplate, we use: <meta name="viewport" content="width=device-width">
  • 5. 1. viewport - width Question: Should I always use width=device-width? Answer: If your site is a fluid layout desktop design, using it is generally better when viewing the site on mobile devices. If your site is a fixed layout desktop design, it’s up to you, doesn’t matter. If your site is a mobile specific design, just use it.
  • 6. 2. viewport - target-densitydpi Before talking about this property, let's briefly talk about pixel. The easiest way to explain this is to think about your desktop, on the same monitor if you adjust resolution, your desktop icons look smaller when you use high resolution, and bigger when you use low resolution. Android introduced target-densitydpi. When you set target- densitydpi=device-dpi, with the same physical phone size, images/text will look smaller on a high resolution device, and bigger on a low resolution device.
  • 7. 2. viewport - target-densitydpi Question: So what’s the problem with target-densitydpi=device-dpi? We are fine with it when we adjust our monitor right? Answer: The problem is that a high resolution device can be twice as high as a low resolution one, with the same physical device size, such big difference can make your pixel related everything shrink into half the size.
  • 8. 2. viewport - target-densitydpi Question: Is there a iPhone equivalent of target-densitydpi=device-dpi Answer: Not really. In iPhone, you can only specify width=device-width. Regardless of whether it's iPhone 3 or 4, the device-width is always 320px in portrait mode. Question: How about Window Phone? Answer: Windows phone also uses 320px as device-width in portrait mode, which is why it's good to make Android behave the same way as iPhone and Windows Phone. The consistency will make it much easier when styling.
  • 9. 3. viewport - scaling On most smartphones, default scaling may occur that will 'zoom' your pages on mobile browser. To prevent user scaling, you can use initial-scale=1.0. So now, below is the full version of our 'viewport boilerplate': <meta name="viewport" content="width=device-width, initial-scale=1.0">
  • 11. 4. CSS Media Queries - max/min-device-width If you want to have a CSS style that only smartphones will pick up, use: @media only screen and (min-device-width : 320px) and (max-device-width : 569px) {...} Example of HTC Desire HD, it has a width of 533 in landscape mode
  • 12. 5. CSS Media Queries - max/min-width max-width and min-width are updated when you rotate the screen, your max-width in portrait mode become max-height in landscape mode @media only screen and (min-width : 480px) { .box { width:200px; height:200px; background:yellow; } } @media only screen and (max-width : 320px) { .box {width:200px; height:200px; background:red; } } below screen will be rendered when the above style applied:
  • 13. 5. CSS Media Queries - max/min-width Question: Is max/min-width the same as max/min-device-width? Answer: If you set width=device-width, then max/min-width is the same as max/min-device-width inportrait mode, and different when in landscape mode. In short, the difference is max/min-width will update when you rotate the screen, whereas, max/min-device-width won't.
  • 14. 6. CSS Media Queries - device-pixel-ratio device-pixel-ratio could help you know the resolution of the device screen, iPhone 4 and certain other smartphones have pixel ration equal or higher than 1.5, so if you want to target high resolution devices, you can use the media query below: @media only screen and (-webkit-min-device-pixel-ratio : 1.5), only screen and (-o-min-device-pixel-ratio: 3/2), only screen and (min-device-pixel-ratio : 1.5) { .imagebox {background:(url:"images/high/demo.jpg");} } Be cautious!!! when you are using it in the above way, the image will be downloaded even if the page doesn't fit the rule above.
  • 15. 7. CSS Media Queries - orientation iPad introduced 'orientation' to help with detecting orientation change, below is how you can specify landscape and portrait style /* iPads (landscape) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) { /* Styles */ } /* iPads (portrait) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) { /* Styles */ }
  • 16. Thank you Brought to you by Mobile Boilerplate http://html5boilerplate.com/mobile/ Shi Chuan, Paul Irish, Divya Manian