match pixel size of element on iOS screen with CSS - css

I am trying to create a notification container with CSS that is the same size as notifications on iOS on my iPhone 6S.
I have created screen grabs of portrait and landscape. When I view the images the sizes of the notifications in pixels are 718x262 and 841x262 respectively.
When I create the notifications with the same height (262px) they are displayed on the device differently 200px in portrait and 357px in landscape).
https://www.dropbox.com/sh/bmkv2gua62r4zly/AAC0xPZIURWZFwCb9pFzDk1Da?dl=0

Adding viewport meta tags fixed the issue
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="initial-scale=1.0">

Related

Shrink the entire view when resizing the window

I want to shrink the entire view when resizing the window. In mobile view, the view should be a shrunken version of the desktop view. Something similar to the https://www.cbioportal.org/ website. If we resize, the entire view is being shrunken. In the frontend i'm using Angular and bulma. How could I achieve this?
Don't use the "responsive" meta tag:
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
This will revert to default behavior of browser which shows the entire viewport width.

Using viewport to force all screens to 640px wide

I am trying to force all mobile devices to have a rendered screen size of 640px wide. I've used:
<meta name="viewport" content="width=640">
Unfortunately, when I emulate screen resolutions in Chrome, the page sizes completely differently between different devices.
If I emulate a Note 3, it looks far different than an iPhone 4.
I've also tried doing:
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
But this only works for any screen who's initial scale or pixel ratio is set correctly. For example, the note3 has to be set to initial-scale=.5623 for the page to look like it's 640px wide, but that's not the case for the iphone.
What am I missing??

Orientation Change adds margin/padding

singforpleasure.nicktoye.co.uk on the iPhone/mobile device breaks the layout when you go from portrait to landscape to portrait. When you return to portrait it adds some extra spacing to the right.
Is this a bug?
You must adapt the meta viewport to:
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
Then it should be fine.

Mobile resolution and CSS aspect ratio

I'm building web application using RWD. I've written media queries for different resolutions say 1024, 768 and 320.
I'm using below metatag to decide page width
<meta name="viewport" content="width=device-width, initial-scale=1" />
There are few devices e.g. iPhone 5 with resolution - 1136×640. When I'm opening my webpage in iPhone its displaying 320 layout in landscape mode where as its resolution says its 1136px wide.
I know it has CSS pixel ratio as 2 but not sure logic between CSS pixel ratio, media query width and device resolution calculation.
Is there are any article or link that explains this and will tell why its displaying 320 layout for iPhone.
Thanks in advanced.
Try using this meta declaration instead:
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

Scale down Mobile Safari viewport width when iPad is in portrait orientation?-

I am working on a website which is designed to work best when viewed in landscape mode on iPad. Everything is in a 1024px wide <div> container. However, I am still required to scale down the viewport so when the user turns the iPad into portrait orientation, the user does not have to zoom out or scroll horizontally to see everything on the page.
Currently I have this <meta> tag in my <head>:
<meta name="viewport" content="width=1024px, initial-scale=1.0, maximum-scale=10.0" />
Everything displays fine when the page is viewed in landscape mode, but I can't get the abovementioned required portrait behavior to work. I tried changing the initial-scale to 0.75, and the exact opposite happens: everything fits in portrait mode, but there's extra horizontal space when iPad is in landscape mode.
Is there any CSS, Javascript or special viewport setting I can use to get this to work?
P.S. I cannot use user-scalable=no.
You can even add the orientation properties within the same CSS that you use for desktop browsers...Just need to add the following;
#media only screen and (device-width:768px)and (orientation:portrait)
/*iPad Portrait orientation styles */
#media only screen and (device-width:768px)and (orientation:landscape)
/*iPad landscape orientation styles */
Again remember for iPad, device-width is always 768px irrespective of the orientation...I know it's confusing, but that's the way it is...
You can also check out a very good tutorial on the same at
http://itunes.apple.com/in/app/designmobileweb/id486198804?mt=8
You may be able to use orientation specific CSS like this:
<link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css">
<link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css">
In that case you will likely have to set the viewports setting to the devices max width and take care of the actual width of the content using CSS. For example, wrap everything in a div with the appropriate width for each orientation, 1024px or 768px (minus the status bar and browser chrome is neccessary).
<meta id="viewport" name="viewport" content="initial-scale=1.0;minimum-scale=1.0; maximum-scale=1.0" />

Resources