How can I target devices which are wider than 1000 pixels? That is, including iPad in landscape mode and most desktops but excluding iPad in portrait mode.
I have found how to target iPad specifically:
/* 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 */
}
However, I would prefer if my media queries could be shaped by at what widths the content prompted layout changes rather than by specific devices.
If I understand your question correctly, you don't need to try and target specific devices at all.
In your main CSS just include:
#media (min-width: 1000px) {
/* CSS styles for viewports 1000px and up */
}
and in the head of your page include
<meta name="viewport" content="width=device-width, initial-scale=1.0">
EDIT
Here is a working example which you can check in an iPad:
Live: http://fiddle.jshell.net/panchroma/Bn4ah/show/
Code view: http://fiddle.jshell.net/panchroma/Bn4ah
Good luck!
While that article you referenced from CSS-Tricks is a very handy reference (and Chris Coyier is my nerd-idol) it may be a bit misleading. Media queries at their core are just fancy if statements, and if the entire statement evaluates as true, then the corresponding style sheet or style rules are applied, following the normal cascading rules.
Let's look at a common media queries:
#media screen and (min-width: 768px) { ... }
Notice the screen parameter. It says nothing about the device width nor browser chrome. Read in plain English, it says "if the media we're working on is the screen, and if that screen is a minimum of 768px or bigger, use these styles.
So, to answer your question: to target screens that are larger than 1000px wide, try this:
#media screen and (min-width: 1000px) { ... }
Just remember that you're targeting all screens at least 1000 pixels wide. If you need to target specific devices, I recommend using JavaScript to handle specific UserAgent targeting.
Related
I applied some media queries to my css. These appear to be effective only when browsing the website from the devices I designed them for, or when - while using the browser Responsive Design Mode - the touch simulation is turned on.
If I simply drag the screen to reduce its size, the website doesn't appear to be responsive.
Any idea on why is happening?
These are the queries I'm using:
/* Smartphones (portrait and landscape) ----------- */
#media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Style */
}
/* iPads (portrait and landscape) ----------- */
#media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* Style */
}
/* Large screens ----------- */
#media only screen and (min-width : 1824px) {
/* Style */
}
And here you can see the website GH repo:
https://bianchinicecilia.github.io/ceciliabianchini/index.html
Thanks in advance for your help! :)
I think I can help you.
You're using deprecated media queries. You don't need to use -device-, just min-width or max-width. I also noticed that your site is without the viewport meta tag: <meta name="viewport" content="width=device-width, initial-scale=1.0">. This is very important too!
Finally, review all meta tags because some sizes are conflicting.
List of media queries:
https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
About Viewport:
https://developer.mozilla.org/en-US/docs/Web/CSS/Viewport_concepts
I'm doing a website that is supposed to work on mobile devices. I have researched about the subject and every website recommends that I use a different media query for each device I intend the website to work on, for example:
/* ----------- iPhone 4 and 4S ----------- */
/* Portrait */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
}
/* Landscape */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 480px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {
}
/* ----------- iPhone 5 and 5S ----------- */
/* Portrait */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: portrait) {
}
/* Landscape */
#media only screen
and (min-device-width: 320px)
and (max-device-width: 568px)
and (-webkit-min-device-pixel-ratio: 2)
and (orientation: landscape) {
}
/* etc... */
However I feel it would be much much simpler to just use one media query for landscape and another for portrait orientation, but I haven't found anyone recommending that.
I imagine you may want to design something more specific for tablet. But speaking only about mobile phones, I can only thing of a reason to have different media queries for each device if you want something CRAZY specific.
Is there any reason for it?
Should I add a media query for each device or is it "safe" to continue with only two media queries?
That's absolutely fine. Don't forget to add the responsive meta tag to every page:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
and then use media queries as you resize your preview window width and height. That'll make the website same as the desktop version.
You can totally pull it off with just one or two media queries. I do it all the time for tablet and then for mobile in fully responsive sites that work on all devices. Those type of fleshed out media queries are for very specific sizes when the developer wants to have a set version of the site for this size and that size.
#media screen and (max-width: 1024px) {
/* Landscape style changes */
}
#media screen and (max-width: 768px) {
/* Portrait to mobile style changes */
}
#media screen and (max-width: 450px) {
/* Maybe one more because that header text doesn't fit anymore on smaller screen */
}
It will be as good the rest of your code, but if you have clean css this should not be a problem.
There is NO problem with it, as far as I see it.
You make your site Responsive for not only the browser window (resizing) but also Adaptive on specific devices. Adding and on those media queries is good too if you see how it behaves (target) on Android phones since your breakpoint basis are iPhone.
You may consider creating another .css file for phone/mobile, the same goes for others (Tablet, TV, etc).
w3schools - media queries
Put all your mobile queries on separate .css. Facebook did the same m.facebook.com.
I am using bootstrap to build a client's site and I have come unstuck when trying to target landscape and portrait orientation on mobile in order to add some specific styles for both viewports. How do I target portrait and landscape orientation for mobile styles? I need to add specific styles at 320px breakpoint and certain styles at 480px breakpoint. With my current media queries this is not working Currently in my stylesheet I have the following:
/* portrait phones */
#media only screen and (max-width: 320px) and (orientation:portrait) {
/* Styles */
}
/* landscape phones */
#media only screen and (min-width: 321px) and (orientation:landscape) {
/* Styles */
}
If I put styles in for landscape however I don't think they are being picked up. Every time I make a change and then refresh my Iphone I don't see any difference. Im thinking maybe my media queries are wrong? If there is a better way to target mobile states I would greatly appreciate any help.
Try to use:
#media (orientation: portrait) and (max-width: 400px) {Fooobar}
#media (orientation: landscape) and (max-width: 400px) {foobar}
I managed to resolve this issue in the end by adding a max-width to my 321px media query and was able to target both landscape and portrait mobile orientation. I also found in my header I had: initial-scale=1 which seemed to be causing the problem and after removing it I was able to target the mobile breakpoints I needed.
/*Portrait phones */
#media (max-width:320px){}
/* Landscape phones and down */
#media (min-width: 321px) and (max-width: 480px) {}
I need to set my site on desktop (1024 * 768) and ipad, but I can not separate his Vizualization.
I'm using in Ipad:
# media only screen and (min-device-width: 768px) and (max-device-width : 1010px)
and desktop:
# media (min-width: 1020px)
its Works in Firefox, but not Chrome.
Rather than trying to target specific devices, it's arguably better to set appropriate breakpoints specific to your layout. That is, gradually narrow your browser and observe the points at which this particular design needs to reflow. Then set styles that apply to those points, and let each device receive whatever layout works best within its dimensions.
So, in the head of your page, I recommend you place this:
<meta name="viewport" content="width=device-width">
and then in your style sheet, use something like this (the numbers are arbitrary):
/* default styles, perhaps for basic mobiles and older browsers */
/* end default styles */
#media only screen and (min-width: 1025px) { }
#media only screen and (min-width: 701px) and (max-width: 1024px) { }
#media only screen and (max-width: 700px) { }
#media only screen and (min-width: 320px) and (max-width: 480px) { }
There are so many combinations of this that the above is just a rough example. You don't always need max and/or min. It depends on the layout.
There's also an argument for using ems instead of px, but I won't go there for now. :)
Why not just cascade down?
#media screen and (max-width : 1024px){ /*Styles*/ }
#media screen and (max-device-width : 768px){ /*Styles*/ }
1024x768 is iPad size anyway.
If you go here on an iPad, and click through to Chapter1 > Chapter 1 > Get started... you will see after a loading screen the Chapter 1 page.
Basically what this is, is html embedded into an iframe being pulled together by HTML5 and JavaScript. the html in this iframe calls its own css sheet called other.css. The html file that pulls this all together is calling a stylesheet called styles.css.
Obviously I want in portrait view the content area of this iframe to be smaller than in landscape. I am using the css in other.css :
#media only screen and (device-width: 768px) and (orientation:landscape) {
#content {background:green;}
}
#media only screen and (device-width: 768px) and (orientation:portrait) {
#content {background:blue;}
}
The problem is that its like it doesn't even see the portrait css. I have tried a dozen different ways ( this is supposed to be the correct way and works for the styles.css adjustments to the whole page) but it will not recognize it. It will only use the landscape. Its not as though it wont see the media queries, it pulls the landscape CSS. But WILL NOT use the portrait. Really weird. If you see green for the bg in portrait and landscape its ignoring the portrait. If you see blue it's working. How can I achieve this?
If I get rid of landscape CSS, it prefers the default to the portrait. makes no sense. Could the iframe be hindering its pulling in new CSS upon orientation change?
You should target min or max device widths or you will miss out devices.
/* 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 */
}
from http://css-tricks.com/snippets/css/media-queries-for-standard-devices/
Here's an explanation why you probably shouldn't even be that specific http://catharsis.tumblr.com/post/501657271/ipad-orientation-css-revised
what you could try doing is creating two different stylesheets specifically for desktop & Tablet so;
<link rel="stylesheet" media="screen" href="css/stylesheet1.css"> <!--Desktop-->
<link rel="stylesheet" href="css/tablet-nav.css" media="screen and (min-width: 800px) and (max-width: 1024px)"> <!--tablet-->
and dont forget to add;
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/quick-tip-dont-forget-the-viewport-meta-tag/
http://webdesignerwall.com/tutorials/css3-media-queries