#media query is not working in case of iPhone 5 and iPad 4 OS. I have used following CSS for styling each OS and device for different screen.
I explicitly checked that my iPad and iPhone width and height and based on that only i have kept the media queries. This works fine on ANDROID OS.
/*#media print {*/
/* iPhone 5 (Portrait) */
#media screen and (max-device-height: 568px) and (orientation: portrait) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 290px;
height: 473px;
}
}
/* iPad 4 (Portrait) */
#media screen and (max-device-height: 1024px) and (orientation: portrait) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 735px;
height: 929px;
}
}
/* iPad 4 (Landscape) */
#media screen and (max-device-width: 1024px) and (orientation: landscape) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 990px;
height: 673px;
}
}
/* Samsung 10.1 inch (Portrait) */
#media screen and (max-device-height: 1280px) and (orientation: portrait) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 790px;
height: 1140px;
}
}
/* Samsung 10.1 inch (Landscape) */
#media screen and (max-device-width: 1280px) and (orientation: landscape) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 1230px;
height: 680px;
}
}
/* Samsung 7.0 inch (Portrait) */
#media screen and (max-device-height: 1024px) and (orientation: portrait) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 570px;
height: 875px;
}
}
/* Samsung 7.0 inch (Landscape) */
#media screen and (max-device-width: 1024px) and (orientation: landscape) {
#map_canvas {
border: 1px dashed #C0C0C0;
width: 990px;
height: 455px;
}
}
#media all and (orientation: landscape) {
html, body {
height: auto;
}
}
Each time i tested with various changes in above code, I am getting the LAST CSS being referred for applying the style.
I found one link, (which i have not yet tried but going to try soon as mac is available) but have question about that too (iphone/ipad media query issues). Can anyone explain the reason behind that Is pixel ratio matters in this case??
Excerpted from https://mislav.net/2010/04/targeted-css/
You should be aware that orientation media query, although supported on the iPad, doesn’t work on the iPhone (tested with v3.1.3). Fortunately, size queries like width and device-width work, so layout-switching is possible without JavaScript with some combination of those.
The reason is because the new Apple devices have a higher pixel ratio density. You should put this meta tag in the head of your document and your media queries will work everywhere:
<meta name="viewport" content="width=device-width">
By the way, the higher pixel ratio for the new apple products is called "retina display."
If you do have access the iPhone, ipad, etc... try viewing this website:
http://mattstow.com/viewport-size.html
on those devices to see the viewport size of the device. Then, add the meta tag, and you will see that the viewport size changes.
Related
I'm currently developing an HTML email and I've written some media queries for the iPhone as follows:
/* ----------- iPhone 6+, 6S+, 7+ and 8+ --------- */
#media only screen
and (min-device-width : 414px)
and (max-device-width : 736px)
and (orientation : portrait)
{
.email-container {
min-width: 414px !important;
}
.email-header{
padding: 1.2em !important;
}
}
Naturally, this media query doesn't get triggered. :-)
Instead, when I add the following styling to the head, it affects the HTML:
/* Nexus 5X, Nexus 6, Nexus 6P, Pixel, Pixel XL, Pixel 2, Pixel 2 XL*/
#media only screen
and (min-device-width : 411px)
and (max-device-width : 731px)
and (orientation : portrait)
{
.email-container {
min-width: 411px !important;
}
.email-header{
padding: 1.2em !important;
}
}
From what I understand and based on a bit of research, link, link, the device dimensions for the iPhone 6+,6S+, 7+ are 414px X 736px.
Why are the media queries for 411px X 731px devices getting triggered?
You have the widths and heights mixed a little. Try the below code
#media only screen
and (max-width : 414px)
and (max-height : 736px)
{
.email-container {
min-width: 414px !important;
}
.email-header{
padding: 1.2em !important;
}
}
The code looks for a max device width and max device height now with orientation as portrait. Which is what your research brought up:
From what I understand and based on a bit of research, link, link, the
device dimensions for the iPhone 6+,6S+, 7+ are 414px X 736px.
Hope this answer works for you.
The image that I use for my background (which is fixed) displays at 100% in Web format, but when I emulate it on Ipad (1024x768), the image stops adapting to the width of the screen and it just fills about 70% of the screen height.
This is the CSS that I've used for the website format:
.body{
background-image: url("/img/bg.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% auto;
height: 5700px;
width: 100%;
}
This is the CSS that I've used for the Ipad style:
#media screen and (max-width: 1024px) {
.body{
background-image: url("/img/bg.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 100% auto;
height: 5700px;
min-width: 1024px;
}
}
I've tried min-width: 1024px; beacause I found a similar question with that suggestion, but it hasn't worked.
As stated here viewport units caniuse , using viewport units can ( and will ) cause problems in iOS because
iOS 7 Safari recalculates widths set in vh as vw, and heights set in vw as vh, when orientation changes.
iOS 7 Safari sets viewport unit values to 0 if the page has been left and is returned to after 60 seconds.
vh on iOS is reported to include the height of the bottom toolbar in the height calculation, and the width of the sidebar (bookmarks) in the vw width calculation.
So i suggest you use media queries and target different iOS resolution both for portrait and landscape. I know, it's a meticulous task but if you have a serious project for a serious customer , you have to deliver serious product
See here > iosres
For example
/* iPad with portrait orientation.*/
#media all and (device-width: 768px) and (device-height: 1024px) and (orientation:portrait){
.body{
height: 1024px;
}
}
/*iPad with landscape orientation.*/
#media all and (device-width: 768px) and (device-height: 1024px) and (orientation:landscape){
.body{
height: 768px;
}
}
/*iPhone 5 with aspect ratio*/
#media screen and (device-aspect-ratio: 40/71) {
.body {
height: 500px;
}
}
or you could use jQuery or javascript , for example
$(".body").height($(window).height())
this will equal body height to window height
Try using width: 100vw. vw means viewport width, so this should make the background take up the full width of the viewport.
Thanks to #Traver I've found the answer:
.body{
background-image: url("/img/bg.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: 200vh;
height: 5700px;
width: 100%;
}
I just had to change the background-size units to vh and remove auto (but I've tested with it too and it's worked). Giving it a number of 200vh is enough to scale it full width and height.
EDIT: Mihai T's answer is the best one. Check it.
I need query for mobile iPhone 5 and galaxy S4 landscape view...
Her is my code but something is not ok here.
#media
(max-width : 800px){
// style
#media
(max-width : 360px){
//style
On resolution 360 evrything is ok, What i need to enter for landscape view.
Here is EXAMPLE
From this site:
iPhone 5 in landscape
#media only screen
and (min-device-width : 320px)
and (max-device-width : 568px)
and (orientation : landscape)
{
/* STYLES GO HERE */
}
Samsung Galaxy S4 Landscape (from here)
#media screen (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)
and (device-width: 1920px)
and (orientation: landscape) {
/* Your styles here */
}
Use device-aspect-ratio for iPhone 5 - it does not have a 16:9 aspect ratio. It is in fact 40:71.
iPhone 5 only:
#media screen and (device-aspect-ratio: 40/71) and (orientation:portrait) {
/*style here*/
}
Galaxy S4 only:
#media screen and (device-width: 320px) and (device-height: 640px) and (-webkit-device-pixel-ratio: 3) {
/*style here*/
}
I'm trying to set up a manualy splash-image across devices. I'm doing so by checking for orientation (touch devices) or screen width vs. screen height (none touch) and set a url accordingly.
Then I add this CSS rule via Javascript:
document.styleSheets[3].insertRule('.initHandler:before {
background: url('+x+') no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}', 0)
With x being the image to be loaded depending on orientation and screen size.
My problem is this works fine in landscape mode, but on my iPad in portrait mode, the correct image is loaded (differ depending on portrait/landscape), BUT it is not expanded to fullscreen size.
Question:
Can I not use CSS background-size on iOS in portrait-mode?
Thanks for help!
EDIT:
Just tried on my Android Smartphone. Works fine there. Makes no sense, why it doesn't work on iPad.
Ok. Here is how it's working (Thanks to #iMeMyself):
body {
background: url(...) no-repeat center center fixed;
-webkit-background-size: 100%;
-moz-background-size: 100%;
-o-background-size: 100%;
background-size: 100%;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
So first set it to 100%, then to cover. This way all browser that cannot cover get the 100% value, while the ones that can get the 100% overwritten by cover.
While checking orientation please take note of these points from apple document -
Provide Launch Images :
iPhone-only applications may only have one launch image. It should be in PNG format and measure 320 x 480 pixels. Name your launch image
file Default.png.
iPad-only applications: Create a launch image for each supported orientation in the PNG format. Each launch image must be 1024 x 748
pixels (for landscape) or 768 x 1004 pixels (for portrait).
Universal applications: Include launch images for both iPhone and iPad.
Update Your Info.plist Settings Specify values for the UISupportedInterfaceOrientations and UIInterfaceOrientation
and
Not all browsers recognize the cover keyword for background-size, and as a result, simply ignore it.
So we can overcome that limitation by setting the background-size to 100% width or height, depending on the orientation. We can target the current orientation (as well as the iOS device, using device-width). With these two points I think you can use CSS background-size:cover on iOS in portrait-mode
Here are some other resources I also came across while looking for a solution: Flexible scalable background images, full scalable background images, perfect scalable background images, and this discussion.
According to Designing Websites for iPhone X iOS 11 introduces a new extension for the existing viewport meta tag called viewport-fit, which provides control over the insetting behavior. The default setting is auto, which will not cover the entire screen.
In order to disable the default inset behavior and cause the page to lay out to the full size of the screen, you can set viewport-fit to cover as shown here:
<meta name='viewport' content='initial-scale=1, viewport-fit=cover'>
Without this setting existing techniques used for splash screens and full-size hero images may not display as expected on the iPhone X or other conformant iOS devices.
Code here
It fixing background images for ipad
Just enter sizes according to your image dimentions
/* Page background-image landscape for iPad 3 */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 2) {
.introduction-section {
-webkit-background-size: 2024px 768px !important;
background-size: 2024px 768px !important;
background: url('background-image.jpg') no-repeat center top #000 !important;
}
}
/* Page background-image portrait for iPad 3 */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 2) {
.introduction-section {
-webkit-background-size: 2024px 768px !important;
background-size: 2024px 768px !important;
background: url('background-image.jpg') no-repeat center top #000 !important;
}
}
/* Page background-image landscape for iPad 1/2 */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: landscape)
and (-webkit-min-device-pixel-ratio: 1) {
.introduction-section {
background: url('background-image.jpg') no-repeat center top #000 !important;
-webkit-background-size: 2024px 768px !important;
background-size: 2024px 768px !important;
}
}
/* Page background-image portrait for iPad 1/2 */
#media only screen
and (min-device-width: 768px)
and (max-device-width: 1024px)
and (orientation: portrait)
and (-webkit-min-device-pixel-ratio: 1) {
.introduction-section {
background: url('background-image.jpg') no-repeat center top #000 !important;
-webkit-background-size: 5024px 2024px !important;
background-size: 5024px 2024px !important;
}
}
As far as I'm aware, this method works on all IOS devices. Depending on your other page elements (header etc) you may need to adjust z-index for the &:before psuedo-element.
html {
height:100% !important;
}
body {
height:100%;
min-height:100%;
overflow-x:hidden;
overflow-y:auto;
// use your own class here //
&.body-class {
// #screen-xs-max is a Bootstrap3 variable name //
#media screen and (max-width:#screen-xs-max) {
min-height:100vh;
position:relative;
&:before {
position:fixed;
top:0;
left:0;
right:0;
bottom:0;
display:block;
content:"";
z-index:-1;
background-image:url(background-image.jpg);
background-position:center;
background-size:cover;
// Add this unless you compile your LESS using a preprocessor which adds vendor prefixes //
-webkit-background-size:cover;
}
}
}
}
i'm currently having troubly with a site that i'm converting to a adaptive-website. For some reason i can only get one of the orientations to work on the iPad. If i comment out the landscape styling the portrait styling works on the ipad and visa versa. I really don't understand what it is that i am doing wrong...
These are the media queries that i am using:
#media all and (device-width : 768px) and (orientation: landscape) {}
#media all and (min-device-width:768px) and (max-device-width:1024px) and (orientation:portrait){}
Here is a link to the site www.imarken.dk
The problem is in min-device-width. Try to use 481 instead 768.
Give these a whirl:
#media only screen and (device-width: 768px) {
/* targets iPad */
}
#media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait) {
/* targets iPad Portrait */
}
#media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape) {
/* targets iPad Landscape */
}
I had this same problem today! As it turns out, removing my height=device-height in the meta viewport tag fixed the issue and allowed the CSS to switch between portrait and landscape as expected. Hope this helps!