Exclusive CSS for iPhone/Android - iphone

I'm making a mobile-friendly stylesheet for a page of mine. Is there a simple way to make it show that stylesheet to iPhone/Android users? Or do I have to pull the user-agents and figure it out that way - and how do I do that?
Also - any tools to make this sort of web dev easier?

You could do something like this, if your stylesheet is the same for iOS/android.
<link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="css/mobile.css" type="text/css" />
But if you're trying to detect if it's the iOS OR Android, then you'll need to do detection.
In terms of making mobile dev easier, there's a ton of stuff:
http://www.phonegap.com/
http://www.sencha.com/products/touch/
http://www.appcelerator.com/
http://www.jquerymobile.com/
http://www.jqtouch.com/
There's a few to get you started :)
Hope this helps.

Try this, using navigator.userAgent in JavaScript ;) (courtesy of this awesome post http://css-tricks.com/snippets/javascript/redirect-mobile-devices/):
if ((navigator.userAgent.match(/iPhone/)) || (navigator.userAgent.match(/iPod/))) {
alert("we've got an iDevice, Scotty");
}
if (navigator.userAgent.match(/Android/)) {
alert("Droid me baby");
}

detect what exactly use user, and style for his mobile device
iphone 4
#media screen and (device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2){
.inphone4CSS{}
}
traget Target Samsung Galaxy S2
#media screen and (device-width: 320px) and (device-height: 534px) and (-webkit-device-pixel-ratio: 1.5){
.GalaxyS2_CSS{}
}
more about it(or another devices) you can find here:
Target a specific device

Related

Background on the ipad cut in half

Im trying to finalize this website, and somewhere during the time i was tidying up the code i messed up how the background looks on the ipad and iphone. It looks fine on all other browsers including the native android. theres a slight bug on firefox but im working that out now.
Website in question: http://morzi.com/constantine/
The bio page has a link to an ipad css but just ignore that i was just fooling around trying to fix the issue.
Thanks!
I'm not sure where to begin, and I'm not sure what software you are using to code this but it's definitely not hand coded :s.
Anyways, your CSS is really screwed up.
Three solutions:
Hand code the CSS and in this case you can play around with the background position which will align the background with the content, then you can redesign the picture to see the person on the left.
background-position:top center;
Restructure your HTML and CSS to have the website work in compartments:
|aside|article|aside|
<aside id='left'></aside>
<article></article>
<aside id='right'></aside>
<style>
aside#right,
aside#left {
width:5%;
}
article {
width:90%;
margin:0 auto;//centers the div
}
</style>
Create a media type for mobile devices with specific width like so
#media only screen and (max-device-width: 480px) {//Iphone and below
//css for mobile device
}
#media only screen and (max-device-width: 768px) {//Ipad and below
//css for mobile device
}
I hope this helps and good luck to you :D

Target mobile devices with CSS (iPad, iPhone) but exclude non-mobile devices

I'm trying to target mobile devices (specifically the iPad and iPhone) but using CSS3 media queries the same styling is added to other devices with the same resolution, such as laptops. How can I add mobile device specific styling without adding it to other non-mobile devices too?
So far I'm using this, which adds the css to all devices that are 1024px wide and under, even with the orientation selector:
#media only screen and (min-device-width: 320px) and (orientation:portrait),
(max-device-width: 1024px) and (orientation:landscape){
// Do something
}
EDIT:
For anyone interested, I got this to work just by duplicating the media query but altering the duplicate slightly. It's by far the most efficient way of doing it but the main thing is it works:
#media only screen and (min-device-width: 320px) and (orientation:portrait),
(max-device-width: 1024px) and (orientation:landscape){
// some styling
}
#media only screen and (min-device-width: 320px) and (orientation:portrait),
(max-device-width: 768px) and (orientation:portrait){
// some styling
}
Maybe a look at this, at the section "7.3 Recognized media types", will help you.
Yup: desktop browsers support the orientation media query too.
I don’t think media queries provide a way to detect whether a device is the iPad or the iPhone. They allow you to inspect features of the device (like its width and orientation), rather than identify the device.
What makes your styles inappropriate for non-iPad devices?
I found that all you need is the second media query in your edit:
#media only screen and (min-device-width: 320px) and (orientation: portrait),
(max-device-width: 768px) and (orientation: portrait) {
// some styling
}
It worked like a charm!

iPhone 4 Retina “apple-touch-startup-image” for Web-apps (landscape)

Hope this question hasn't been asked before.
I've got the following working
<!-- 640x920 for retina display -->
<link rel="apple-touch-startup-image" media="(max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)" href="images/iphone4-portrait.jpg" />
i'm aware that the image has to be 640x920 else it will not work
i know that there is no Landscape option for this? or is there?
So...on to my issue, when loading the web app from the home screen in Landscape you can see the page content behind the splash screen (lighter green area in the landscape image below), where the states bar was in portrait
Has anyone out there had this issue, if so how are you getting around it.
Thanks
You can not have a landscape startup image on an iPhone. Landscape images ONLY work on the iPad. Also, you must use the proper size on the iPhone, or it will not display at all.
This will add a Splash Screen to your Web App. Below are the sizes you’ll need for both iPad and iPhone/iPod Touch, these include the status bar area as well.
iPad Landscape – 1024 x 748
<link rel="apple-touch-startup-image" sizes="1024x748" href="img/splash-screen-1024x748.png" />
iPad Portrait – 768 x 1004
<link rel="apple-touch-startup-image" sizes="768x1004" href="img/splash-screen-768x1004.png" />
iPhone/iPod Touch Portrait – 320 x 480 (standard resolution)
<link rel="apple-touch-startup-image" href="img/splash-screen-320x460.png" />
iPhone/iPod Touch Portrait – 640 x 960 pixels (Retina Display high-resolution)
<link rel="apple-touch-startup-image" sizes="640x960" href="img/splash-screen-640x960.png" />
If creating a Web App for iPad compatibility it’s recommended that both Landscape and Portrait sizes are used.
Getting these to work is an utter nightmare.
On git hub (https://gist.github.com/472519) it says the retina should be
<link rel="apple-touch-startup-image" media="screen and(max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)" href="apple_launch_640x920.png" /> - and everybody says it should be the exact size or it won't work yet everybody says different sizes.
On top of that apps seem to cache (maybe not now in iOS5.1 but I am not sure) so you don't have any way of knowing if you have done it right or not if you didn't get it right first time.
I REALLY REALLY REALLY wish Apple would post up code on its dev info somewhere with the definitive answer to this (including iPad Retina) so we could just treat this as the 10minute job it should be rather than wasting hours and hours and hours messing around...:(
I have found the following works on iPad 2 at least- the iPad2 landscape version is actually portrait with the content rotated, so make the landscape version (748x1024) and then rotate 90 CLOCKWISE and you will be good to go.
<!-- startup image for web apps - iPad - landscape (748x1024)
Note: iPad landscape startup image has to be exactly 748x1024 pixels (portrait, with contents rotated).-->
<link rel="apple-touch-startup-image" href="/apple_launch_748x1024.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" />
<!-- startup image for web apps - iPad - portrait (768x1004) -->
<link rel="apple-touch-startup-image" href="/apple_launch_768x1004.png" media="screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" />
What to do with the rest though I dont know, I don't have an old iphone or a retina ipad, and this is all so flakey whether any of it works is anyones guess...
There is no landscape launch screen spec for the iPhone. This is because the iPhone does not rotate its home screen when the device is sideways -- users will always be launching from portrait orientation.
If you insist you need this however, you could just have your regular launch screen be sideways, suggesting to the user they need to turn their phone around.

Media query not working for (min-width:321px)

I'm building a responsive design and everything is fine apart from I can't seem to target iPhone 3g users.
I've added the following media queries but the first one (max-width:320px) doesn't seem to work
#media screen and (max-width: 320px) {
// STYLES GO HERE
}
#media screen and (min-width: 321px) and (max-width: 640px) {
//STYLES GO HERE
}
Am I doing something wrong?
Try max-device-width (max-device-width: 320px); I haven't tried it specifically for non-retina display iPhones, but have found it to help when targeting the iPhone 4 specifically.

Media Queries failing on Android browser

I am trying to develop a web app which applies an appropriate style sheet depending on the device (and its orientation).
I have 5 media queries in total:
//for mobile phones in portrait mode
<link rel="stylesheet" media="all and (max-device-width: 480px) and (orientation:portrait)" href="css/mobile-portrait.css">
//for mobile phones in landscape mode
<link rel="stylesheet" media="all and (max-device-width: 480px) and (orientation:landscape)" href="css/mobile-landscape.css">
//for tablets (iPad) in portrait mode
<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)" href="css/tablet-portrait.css">
//for tablets (iPad) in landscape mode
<link rel="stylesheet" media="all and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)" href="css/tablet-landscape.css">
//for desktop computers
<link rel="stylesheet" media="all and (min-device-width: 1025px)" href="css/desktop.css">
Everything works on the Desktop, iPad and the iPhone (in both browser and web app versions) but the landscape media query fails on Android's browser? Any ideas? Have I got the 'max-device-width' wrong?
That's because most newer android phones are something like 480 wide by 800 tall depending on device, so the way you have yours written, Android Landscape should be picked up by the tablet landscape css. But I think I ran into a similar issue with Android not picking up the stylesheet, so I added this and everything seemed to work...
<meta name="viewport" content="width=device-width">
Do you have this in your head above your stylesheet links?
On the Droid1 - the viewport size is 320 x 569.