1 Comment

Why aren’t CSS colors the same? `in-browser` and `cross-browser`

March 15th, 2012

When you set backgroundcolor of the body to hsla(20,30%,50%,.5), what do you expect as output when you read it out with javascript?

The same result in every browser?
Wrong!

The same  in a particular browser ?
Wrong!

The same in a particular browser  indifferent to the color model (rgba or hsla)?
Wrong again! Only Firefox does it right.

Chromium 17: body { background-color: rgba(166, 115, 89, 0.496094); } 

Opera 11.61: body { background-color: rgba(166, 115, 89, 0.5059) } 

Firefox 10.02: body { background-color: rgba(165, 114, 89, 0.5); }

Example

Setting and reading out the color value a 100 times doesn’t change the color in the end, so it seems a result of the javascript floating-point arithmic quirk without any serious implications.

No Comments

Enable CSS transitions / transforms after pageload

March 6th, 2012

CSS transitions or transforms are triggered by user action like hovering or toggling classes.

To make CSS transitions occur at pageload we have  do a simple two step JavaScript trick: add a class and remove that class again to trigger the transition.

1. put this in the header of your page to add an extra class during loading

<script type="text/javascript">
document.documentElement.className += " js";
</script>

It will add js as a class to the html element.

2. Remove that extra class after pageload.

How?

with jQuery

$(document).ready(function(){

document.documentElement.className = ""

}

Without the  jQuery framework

document.addEventListener('DOMContentLoaded', function () {
document.documentElement.className = ""}, false);

or a very simple

setTimeout(function(){
document.documentElement.className = ""
},200);

In you CSS file make the transition

body{opacity:1;
transition:opacity 1s ease;}

.js body{opacity:0}

This approach has the advantage that no-javascript users see the final result (opacity 1) and will miss the transition.

Example:

No Comments

Cross-browser CSS transition problems

February 28th, 2012

The great CSS compatibility tables of PPK show good cross browser support for transitions on the width or height property.

Actually the reality is different, there are problems and they are related to height/width changing from percentage/number to another value, from number to percentage and vice versa and most problematic to auto,

You can’t make transitions to height auto, which is IMHO plain stupid. Maybe there are reasons like that the value `auto` is unknown and has to be calculated first. Still, you can read out the property height as a value and  it’s the thing you want as a webdeveloper and it worked in some earlier versions of Chrome if I recall correctly.

Furthermore in the following example the animation renders differently in different browsers.

The latest Firefox (10.0.2) can animate from numbers to percentage. Opera and Chrome can’t, Firefox 9 couldn’t.

No browser can animate to a value auto, which is IMHO we want all.

No Comments

CSS vendor prefix issues

February 16th, 2012

Vendor prefixes are the verbose code you see in new `HTML5` sites, in which browser vendors test their new CSS3 rules, when specs are in proposal time or under development.

Something like:


-o-transition: opacity 1s ease-in 1s; //opera
-moz-transition: opacity 1s ease-in 1s; /firefox
-ms-transition: opacity 1s ease-in 1s; // internet explorer
-webkit-transition: opacity 1s ease-in 1s; // safari , chrome
-khtml-transition: opacity 1s ease-in 1s; // konquerer , linux
transition: opacity 1s ease-in 1s; // all when it's official spec

The problem is that most developers seem to do just this:

-webkit-transition: opacity 1s ease-in 1s; // safari , chrome

So they only support webkit browsers and that is plain dumb. At least you should always add the rule without any prefix. That means eventually it will work in every browser that supports it.
Typing all the rules is a pain in the ass, so most developers only do webkit, probably also because Apple invented quite a lot for transitions etc. At that time it was not supported by any other browser, so why on earth should you add code that has no meaning. Well because you care about the future and care about different minded people.

Two helpful solutions

First there are macro’s for IDE’s to type one rule and auto generate the other ones. Here is a CSS vendor prefix macro for Netbeans. Not much of a hassle.

Secondly you can call userJS to the rescue, userJS is like userCSS a rather underestimated part of the internet, but yet a very valuable one. It let you overrule CSS rules or run own JS in websites.

For Opera add this as a userJS:

opera.addEventListener('BeforeCSS', function(userJSEvent){
userJSEvent.cssText = userJSEvent.cssText
.replace(/-(moz|ms|webkit|o)-(border|text-overflow)/g,'$2')
.replace(/-(moz|ms|webkit)-(gradient|transform|transition)/g,'-o-$2');
}, false);

Source here

It will automatically rewrite all -webkit- rules to -o-  rules in Opera, so all the webkit  demo’s will start to work. (if Opera supports them)

Caveats

  • Code (css specs) can change during development.
  • Implementations differ between vendors.

Of course these are workarounds, I still think developers should add all vendor prefixes to their code. It can be automated in an IDE like with mentioned macro for Netbeans or in deployment.

No Comments

Smartphones can be stupid too, and that makes Apple Evil BTW

February 15th, 2012

Why can’t the iPhone / iPad download files?

The standard mobile Safari cannot download all types of files. It can only download files of the type : Word, Excel, Powerpoint and PDF files.

Why on earth does a company design a browser that cannot download files. That is a disgrace, and an insult to the way internet works. It’s getting more smelly, when you realise it can download Office files from one specific vendor Microsoft but not from any other. That isn’t exactly treating people the same, that isn’t exactly improving competition. That’s an insult to the free world. That is limiting competition. That’s anti-competitive behaviour. And it’s simply unfair. We should use open standards in communication, we want to communicate in a way everyone can understand, or at least everyone can learn to understand for free, well that is by investing time, but not money.

Apple has created a phone that can only shop in their own shops, you can’t buy downloads somewhere else. ( iPhone/iPad allows customers to access the iTunes Store to download audio and video files, AR 2010)

Read the rest of this entry »

No Comments

Don’t do Evil

January 26th, 2012

AKA the day I stopped using Google. I don’t like the new policy of Google by pushing other services, like Google + to any Google account. It seems that I have a Google website now as well.

The day I started Google I can’t exactly recall, must be back in the 90’s, at least it feels that way, a  friend asked me which site I normally used for search the internet. AskJeeves, Lycos, Hotbot or AltaVista. He said, try Google it’s clean and very fast. I tried it, liked it, and started it using form that day on.

Since then I tried Yahoo a couple of times, but no good. Yahoo doesn’t seem to have heard of the Levenshtein function, so it never corrected my typo’s which is , considered my bad typing, invaluable for any search engines. I always wondered why only Google implemented it.

MSN, Live or Bing has never been an option to me, since Microsoft started accidentally / deliberately  blocking competitors.

This year Google broke my spatial keyboard navigation in my Opera browser. Google made a kind of key-logger from their homepage, every key I accidentally hit on my computer is sent into the search box and up to the Google servers. I can’t move focus of the search-box, so the walk through the several links with Opera’s superb keyboard handling is borked.

And I got sick of all that Javascript running, I got sick of all the cookies that personalized my search results. I live in Amsterdam, but I prefer to have the same view on the world as someone in London, Moscow or New Delhi.

Is DuckDuckGO the way to GO? At least their privacy policy is better.