blog home

How to apply mobile CSS to smart phone devices

Posted by Jen in coding front-end, trends on December 9th, 2009

screenshot1When I am talking about mobile css, I am looking for safari in iphone, blackberry default browser and this new born but the mobile browser for majority to be - opera mini. These days, in spite of the fact that the third generation phones - smart phones have made the majority share of cell phone market in US, unfortunately the mobile web hasn’t come to a universal standard that we can apply like we do to those modern computer browsers.  As a result, when designing a website for mobile, it usually takes more effort to find a solution to browser compatibility and accessibility. And funnily, most smart phones don’t consider themselves as handheld device, thus this “handheld” media for CSS doesn’t work for them:

<link media=”handheld” href=”mobile.css” type=”text/css” rel=”stylesheet” />


First of all, iphone and its default browser Safari.

Yes, iphone made everything easy for everyone, not just consumers but also iphone application developer as well as web designers :) So this approach is rather simple comparing to all other smart phone devices.

<link media=”only screen and (max-device-width: 480px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />

In order to include all other devices which consider themselves as handheld, we tweak this line to be more general:

<link media=”handheld, only screen and (max-device-width: 480px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />

To be even safer, there are times, the device width is 320 pixel or less. So here we are:

<link media=”handheld, only screen and (max-device-width: 320px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />
<link media=”only screen and (max-device-width: 480px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />

Everything works perfectly well with these two lines, except when you come to W3C CSS validator. Yes, W3C doesn’t recognize the mobile style lines, and it doesn’t let them pass through validation. And there is really nothing you can do about it. for more info, you can see some discussion here: http://csscreator.com/node/28171

Blackberry and its default browser.

Blackberry doesn’t pickup any mobile style sheet no matter what media you set to it, not handheld, not width 480px or 320px. There is only one way to give blackberry a mobile looking page - using javascript and direct the page to a blackberry. Below is the script that works. I also tried to apply some mobile style sheet without directing the page to another, but unfortunately didn’t work. more details hereinafter:

<script type=”text/javascript”>
var deviceBB = “blackberry”;

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();
var cssFile = “mobile.css”;
//**************************
// Detects if the current browser is a BlackBerry of some sort.

if (uagent.search(deviceBB) > -1) {
//document.getElementById(’blackb’).href = ‘mobile.css’; // this doesn’t work
window.location = ‘home_bb.html’;

//document.write(’<link href=”‘+cssFile+’” type=”text/css” rel=”stylesheet”>); //this doesn’t work either

}
</script>

Opera Mini

It’s a cool mobile browser, which works well with most smart phones - blackberry, iphone, treo palm, etc. To display your mobile CSS on this browser, all you need is still the two lines:
<link media=”handheld, only screen and (max-device-width: 320px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />
<link media=”only screen and (max-device-width: 480px)” href=”mobile.css” type=”text/css” rel=”stylesheet” />

There is this Opera Mini simulator http://www.opera.com/mini/demo/, which makes it possible to test your mobile styles without a mobile phone, however, it only gives you FALSE result. So don’t use it for testing. Install it to your mobile phone and do the real test from there!

Issues you see in real mobile phones but not in simulator:
Opera Mini doesn’t pick up the font size setting in css. Here is the sentence I got from wikipedia:  Opera Mini supports only one font, which can be set to “Small”, “Medium”, “Large”, or “Extra large” size.

http://en.wikipedia.org/wiki/Opera_Mini

The default setting of font size in mobile phone is “medium”. Be aware of this issue when you design the mobile styles, if you are targeting Opera Mini as your mobile browser - use one font size - medium for all text and let it fit in the page.

Another trick of CSS for printing in FF

Posted by Jen in coding front-end on November 12th, 2009

firefoxbugWorking on a printing CSS today, and I found when I tried to print or print preview the page in FF, it only prints/shows the first page, the rest are just blank. This issue only exists in FF browser, all others (IE6-8, Safari) are just fine. So what causes the problem and what’s the solution?

All because of this: overflow: hidden
As soon as I removed it, the print preview is good. However, this overflow:hidden is there for a reason, if you remove it, you have to work on the overflow issues. So printing or overfow? you gotta choose one, or if you are flexibile enough, work around the content to prevent it from being overflown.

Well, Firefox also has bugs… it’s the hard cold fact, so deal with it :)

Many reports about this issue in FF suport:

report 1,  report 2, report 3, look at the comments down there, they are really helpful.

Firefox 3.5 and some interesting articles about CSS3

Posted by Jen in coding front-end, trends on August 28th, 2009

ff35Firefox3.5 was released a while ago, yet lazy I just updated my FF today. And the direct reason for that is I read two interesting articles, both talking about some fancy CSS effects to the text - one is about the fancy text gradient/shadow effect, one is about text rotation. Both didn’t work on my FF3.0 or FF2.0. :(

All right, so here we go, FF3.5. How much better is it ? It’s faster, it displays fonts even more nicely, and most of all - it supports CSS3 and above! well, while enjoying this advanced modern browser, I also noticed a few cons - forcing to update the add-ons: I have had the great add-ons of firebug, colorpicker and measurelt, they were working perfect and I had no intention of changing them. But as soon as I installed the FF3.5, it told me I have to update them otherwise they won’t be functioning… anyway, I am not so used to the new interface of firebug yet.

Overall I liked FF from day one. It never lets me down with 2.0, 3.0 and the updated 3.5 version, both as a regular computer/internet user and as a web designer. However, to be a web guy, we need to realize that what we produce is for the mass media, instead of for ourselves. Therefore, the two CSS3 tricks about the text effects are just for fun, but definitely not for real work practice. I am taking notes of those codes, but I would say it’s for the future only, when the market share of IE (of all versions), FF3.0 and below, Safari 3 and below and Opera 9 and below are all close to 0%. When will that happen? You tell me. :)

CSS transparency tricky IE6 fix

Posted by Jen in coding front-end on June 29th, 2009

semi-transparentIt’s not hard to implement a semi-transparent block by CSS in all modern browsers. The code is something like this:

.thisblock {
filter: alpha(opacity=65);
-moz-opacity: .65;
opacity: .65;
}

And in your HTML, you have something like

<div class=”thisblock”><img src=”someimage.jpg” />some text after the image</div>

Very eassy, right? It basically covers all browsers - IE7, Firefox, Mozilla, Chrome and even Opera. However, if you try IE6, it’s not working.  Here is one little trick for that… add either width or hight to that div class, then you are done. So the fix will be

.thisblock {
filter: alpha(opacity=65);
-moz-opacity: .65;
opacity: .65;
width: 50%;
}

width can be anything, number, percentage, except “auto” or “inherit”.

With the above trick said, if you really don’t want to define the width or height of a block, but have to implement the semi-transparency in IE6, use <p> instead. With <p>, you don’t have to worry about width or height, because not like <div> which span across the entire row,  <p> automatically wrap around the elements inside it, thus it got a specific width by itself.

A peek at Wordpress - permalinks and SEO sitemap

Posted by Jen in coding front-end, random thoughts on June 24th, 2009

blue-lWhen it comes to free CMS, people usually think of Joomla, Drupal, openSourceCMS, etc. Yes, those are good CMS, and we have made a few websites by using those systems and they all turned out to be great in terms of usability. However, what impressed me the most is the open source PHP/MySQL based Wordpress. With a false impression of a blog CMS, it won’t come up to many un-geeky people’s mind when they want to have a CMS for their regular static page based website. However, as a web professional, I would strongly recommend wordpress as the first CMS choice for most of my clients, because it’s simply great and powerful to develop and use, not just as a blog CMS, but also in all. You can certainly use it for a regular blog free website.

In general, we should think of a blog as a regular website, take its categories the same as navigation menus. The only difference is blog category usually has the URL as www.yoursite.com/category/categoryname1. It’s very easy to turn this URL to www.yoursite.com/categoryname1 which looks just like a regular website subpage. And of course it’s good for the search engine to find your page with less sub-directory as we all know. So how to do that? All you need to do is just go to your wordpress admin page, settings -> Permalinks ->Optional, in the field of category base, simply enter “.” (without quotes of course).

Alright, this is just one little trick of wordpress. It’s just so powerful that it does many things for you already and all you need to do is just a few clicks. One more example. For the google SEO sitemap, when you have wordpress installed, you will never need to manually write up or update this tedious XML file. Go install this google XML sitemap plugin, it takes all your dynamic blog posts as well as static pages to the sitemap file and update it whenever you change something on your site.

One more little trick about this sitemap plugin, if you install your wordpress for only the blog session on your server, and all other pages are located one directory above the wordpress blog session, to include all other pages as well as the blog pages in the sitemap, you will need to upload the sitemap.xml file to the root directly of your site, but not wordpress directory. On the sitemap configuration page, in the “additional pages” section, add the URL of the pages that are located above the blog directory, in “Location of your sitemap file” session, choose “custom location” radio button, fill in the sitemap location manually (should be under root directory). In the sitemap content session, make sure to choose “include homepage”, “include static pages”. Last, click on the link of “build the sitemap for the first time”. Then you are done! No need more work when you add more post or do any updates on the site. Isn’t this cool?

BTW, there are many free and beautiful themes on wordpress.org, and also many interesting blog sites on wordpress.com. You can go get your free blog sites by signing up there.

be cautious when using window.opener

Posted by Jen in coding front-end on June 15th, 2009

I am talking about window.opener in JavaScript. By defining the attributes of this window.opener, you basically got to control some behavior of the parent window. That sounds cool but might be uncool in some situations as well. For example, when you do this, in order to show some page in the parent window:

<a href=”javascript:window.opener.location=’somewhere”>going somewhere in parent window</a>

It may not work at all, because from this current page, you have no control of where it came from. The user may get the URL of this current page, past it to the address bar directly and there will be no parent page of it all. In this situation, the link on this current page will go nowhere.

Well, just some a little issue I fixed from some badly coded website.