I was wondering if it is reasonable to always leave out the px symbol after a 0 in CSS.
For example
margin:0;
instead of margin:0px;
Why am I asking this? Because my friend told me that some minor browsers wouldn’t display the site exact same way if these are left unmarked, for example the mobile browsers in smartphones. Is there any truth in this?
Why we came to this debate is that I found a CSS cleaner online which makes the file size smaller by using this method and others.
Found 2 of these one is CLEANCSS other is CSStidy, of which I havent found a working one.
If u have some formal proof then it would be good for me to convince my friend:D
This question brought about a lot of opinions last time it was asked. But this is the only advise you need to follow. Leave OFF the px (or any unit) after the zero. It is perfectly safe to do so, and ALL browsers will display it identically. :~)
sorry but 0 is 0, there is no need to specify something as absolute at that. I have never used anything but 0 and never seen any browser treat it incorrectly
Because my friend told me that some minor browsers wouldn’t display the site exact same way if these are left unmarked, for example the mobile browsers in smartphones. Is there any truth in this?
I’ve never heard about a problem with phones, esp as most of them are based at least in part on a desktop variety… I don’t remember anyone mentioning phones at all in the other thread. I don’t see anything on Google but I don’t have good Google Fu.
You could test this by making some dummy page with 0 instead of 0px on some element who always has some margin or something, and then go to a phone shop and demand the sales people show you how good or bad their phones can display your site : ) (Jamesicus’ idea) If you see some particular mobile not obeying the 0, you can then see if there’s a bug report for that mobile’s particular browser.
It seems very unlikely to me and the only reason I’ve ever told people to use 0px in place of 0 is for newbs who need to be in the habit of using units at all in the first place. Everyone is correct that the CSS specs say 0 needs no units and I don’t know of an old browser who has an issue with it.
^That’s true of a lot of things, including the final ; in a declaration and whitespace. Not something I personally worry about. I’m also not advocating adding units to 0 measurements, but I can’t honestly say there isn’t some phone somewhere who pukes on it if someone else says that’s true— because I haven’t ever heard anything either way about phones.
Ah, but have you considered -0 (negative zero) now that is an interesting kettle of fish.
Because theoretically it’s not the same as zero even though it is likely to be treated as such in most cases but if you think deeply you’ll see why things aren’t as simple as they seem regarding the use of CSS units… Ignore this post if you want; I have a valid point though.
There are a couple of old mobile devices which had issues with 0 in preference to 0px, but it should be noted that they are no longer in production and used a very old browsing method (pre-iPhone style innovation) so it’s more than just that value which would act funky. My advice is don’t give the unit type and keep it at zero