TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-06-2007, 04:40 PM   #1 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Red face How to fix 95% of the cross-compatibility issues

Wouldn't it be great if with essentially 2 lines of CSS code you could fix 95% of the cross-compatibility issues between browsers?

It's no secret that over the years web developers have had issues with cross-compatibility between such major browsers as Mozilla Firefox and Internet Explorer. Ensuring your code is the same in both has meant big business for aspirin manufacturers. But from now on we will NOT be paying for their roast turkey and Cava champagne come Christmas time. Oh no, no!

Code:
*
{
	padding: 0px;
	margin: 0px;
}
If you place that at the very top if your CSS code, it will return the formatting of your site back to a default every single browser that supports CSS will agree on.

You see, most of the issues wither down to the various margin and padding values that the various browsers set by default. By reducing them all to nothing (zero) you leave yourself with a clean slate to make any website you code from now on, the same in EVERY browser!

The other 5% is down to good code so sign up to TalkPHP for FREE and have limitless access to all the knowledge we have bundled into one forum across hundreds of members!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-06-2007, 05:37 PM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

I'm not sure if that's really the solution to 95% of problems but I do always reset margins/padding, stripping back to a (sort of) uniform base across browsers is a great place to start building up a stylesheet.

It is just a pet peeve of mine but I dislike people putting units associated with zero values. Zero is zero whichever unit you apply, or don't apply -- the latter being my preference.
Salathe is offline  
Reply With Quote
Old 09-06-2007, 05:43 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
I'm not sure if that's really the solution to 95% of problems but I do always reset margins/padding, stripping back to a (sort of) uniform base across browsers is a great place to start building up a stylesheet.

It is just a pet peeve of mine but I dislike people putting units associated with zero values. Zero is zero whichever unit you apply, or don't apply -- the latter being my preference.
Maybe not 95% but it makes as a good title! It'll solve a lot of problems out there as the majority of the issues I see with cross-compatibility issues - the coder has not reset the paddings and margins.

Code:
	padding: 0;
	margin: 0;

I do see what you mean with the above example. 0px is the same as 0em no matter what the units are. I just use it because it's good-practice to apply the unit type. For measurements I use PX and for font sizes I use EM - along with the xx-small, x-small, medium, large, inherit, etc. text values.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-06-2007, 06:42 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

The main issue I run into (I dont code html much) is IE and FF not treating a fixed margin the same, for some reason 20px; means something different to IE.
Village Idiot is offline  
Reply With Quote
Old 09-06-2007, 07:12 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I've come across this problem before. Isn't it when an element is floated and you set a margin, IE will double the margin?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-06-2007, 07:15 PM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
I've come across this problem before. Isn't it when an element is floated and you set a margin, IE will double the margin?
I don't know, I never figured it out.
Village Idiot is offline  
Reply With Quote
Old 09-06-2007, 07:20 PM   #7 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Often an overflow: hidden will sort out these issues. It seems DIVs have a hard time calculating where their borders are.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 09-14-2007, 01:31 PM   #8 (permalink)
The Contributor
 
Shaun's Avatar
 
Join Date: Sep 2007
Posts: 41
Thanks: 0
Shaun is on a distinguished road
Default

Something they are the same, sometimes different, i found it really depends on the element you are using.

Although over time I've learnt to adapt my code to a way where it will work in both IE and FF without any "hacks". Just seems to take time, and then you realize what is going to work properly and what wont.

Sometimes i will have to do the margins and paddings differently on div's to get it to look the same in both, gets quite annoying
Send a message via MSN to Shaun Send a message via Skype™ to Shaun
Shaun is offline  
Reply With Quote
Old 12-05-2007, 05:13 PM   #9 (permalink)
The Wanderer
 
Join Date: Dec 2007
Location: The Netherlands
Posts: 13
Thanks: 3
Jelmer is on a distinguished road
Default

Internet explorer has problems with the so called "box model" this is how it should work. Instead version 5 of internet explorer adds padding inside the size of the box while it should be added as extra width to the box. Newer versions of IE do this as well but only in quirks mode, which can be avoided fortunately.
Jelmer is offline  
Reply With Quote
Old 12-10-2007, 01:06 AM   #10 (permalink)
bdm
The Acquainted
Good Samaritan 
 
Join Date: Nov 2007
Posts: 127
Thanks: 14
bdm is on a distinguished road
Default

Seems like 5 lines of CSS to me.
bdm is offline  
Reply With Quote
Old 12-10-2007, 01:09 AM   #11 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Hehe.

css Code:
*
{ padding: 0px; margin: 0px; }

Better? I can also make it 1 if you like, I'm a very clever boy.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-10-2007, 01:21 AM   #12 (permalink)
bdm
The Acquainted
Good Samaritan 
 
Join Date: Nov 2007
Posts: 127
Thanks: 14
bdm is on a distinguished road
Default



I'm just busting your balls.
bdm is offline  
Reply With Quote
Old 12-10-2007, 07:39 AM   #13 (permalink)
The Contributor
RegEx Guru 
 
Join Date: Dec 2007
Location: Belgium
Posts: 60
Thanks: 6
Geert is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
Maybe not 95% but it makes as a good title! It'll solve a lot of problems out there as the majority of the issues I see with cross-compatibility issues - the coder has not reset the paddings and margins.

Code:
	padding: 0;
	margin: 0;
The 5% where it does not solve the problems relate to form elements like textarea and inputs.

Quote:
This is why so many people zero out their padding and margins on everything by way of the universal selector. That’s a good start, but it does unfortunately mean that all elements will have their padding and margin zeroed, including form elements like textareas and text inputs. In some browsers, these styles will be ignored. In others, there will be no apparent effect. Still others might have the look of their inputs altered.

From: http://meyerweb.com/eric/thoughts/20...set-reasoning/
Eric Meyer's follow-up article, "Reset Reloaded", is definitely worth a read as well.


Quote:
Originally Posted by Wildhoney View Post
I've come across this problem before. Isn't it when an element is floated and you set a margin, IE will double the margin?
True. Can be fixed easily though by applying display:inline; to the floated box.

Read more about it here: http://www.positioniseverything.net/...ed-margin.html.
__________________
Kohana - PHP5 framework
Geert is offline  
Reply With Quote
Old 12-10-2007, 10:00 AM   #14 (permalink)
The Contributor
 
Join Date: Apr 2005
Location: Kent, UK
Posts: 54
Thanks: 0
Dr John is on a distinguished road
Default

You can fix a LOT of cross browser problems by declaring a full doctype. And then setting body {padding:0; margin:0;} (I see little to be gained by setting everything to 0, just more declarations you have to add to set things.)

Many older pages have no doctype of just half of one. Half a doctype can kick IE into quirks mode.

Use either of these (preferably strict)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

(There is nothing to be gained using XHTML as IE doesn't understand XHTML at all, and converts it to html.)
__________________
www.kidneydialysis.org.uk
Dr John is offline  
Reply With Quote
Old 12-10-2007, 10:43 AM   #15 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Yea, doctypes often make IE behave fairly well I find.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-10-2007, 11:01 AM   #16 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

And why is this a security fix? :| What can they do if I don't do that?
Tanax is offline  
Reply With Quote
Old 12-10-2007, 01:51 PM   #17 (permalink)
The Contributor
 
Join Date: Apr 2005
Location: Kent, UK
Posts: 54
Thanks: 0
Dr John is on a distinguished road
Default

It isn't a security fix!
It's a way of increasing the chances that your pages will look much the same in different browsers, and it is often overlooked by beginners.
__________________
www.kidneydialysis.org.uk
Dr John is offline  
Reply With Quote
Old 12-10-2007, 10:23 PM   #18 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

How far do you look back in browser versions to see if the website is okay? I go back to about Internet 6, and I also have a 1.0.* version of Firefox on my PC.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-10-2007, 10:34 PM   #19 (permalink)
The Contributor
 
Join Date: Apr 2005
Location: Kent, UK
Posts: 54
Thanks: 0
Dr John is on a distinguished road
Default

Look at your web stats and ask yourself - is there any need to go further back than IE6, given that IE5.5 has less than 1% of the users world wide.

IE6, IE7, FF and Safari 3 cover 96% of users world wide.
__________________
www.kidneydialysis.org.uk
Dr John is offline  
Reply With Quote
Old 12-10-2007, 10:38 PM   #20 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Precisely. Although I look at W3Schools's statistics.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:20 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design