Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screen and Mobile Stylesheets

Tags:

I've looked through the stack overflow topics on this question, as well as some google search results but I can't seem to solve my issue.

I've created a stylesheet for mobile devices(mobile.css) which is essentially a copy of my main.css with changes to many of the attributes. When I load only mobile.css as the stylesheet it looks great on my iPhone, just how I want it to. However when I put both in, I am getting a mix of both, but more of the main.css

Any idea why?

<head>
<link rel="stylesheet" href="styles/main.css" type="text/css" media="screen" />
<link rel='stylesheet' media='screen and (max-device-width: 480px)' href='styles/mobile.css' type='text/css' />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
like image 416
xIlluzionx Avatar asked Sep 20 '11 03:09

xIlluzionx


1 Answers

According to documents, syntax of loading another file in specific device/condition is like this:

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" media="only screen and (max-width: 400px)" href="mobile.css" />
<link rel="stylesheet" media="only screen and (min-width: 401px)" href="desktop.css" />

This will load only one css file for every single amount of width

For iPhone 4 and new generation iPod touch that have Retina display there is something that you should note. iPhone 4 width is 640 pixels that many developers don't count this width as a mobile browser width. If you add this below meta tag in your document problem will be solved

<meta name="viewport" content="width=320">

This meta tag will impact your images quality. If you want to fix that problem then you need to read about this here.

like image 200
Mohsen Avatar answered Oct 06 '22 08:10

Mohsen