 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
09-06-2007, 04:40 PM
|
#1 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
09-06-2007, 05:37 PM
|
#2 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
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.
|
|
|
|
09-06-2007, 05:43 PM
|
#3 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Quote:
Originally Posted by Salathe
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.
|
|
|
09-06-2007, 06:42 PM
|
#4 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
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.
|
|
|
|
09-06-2007, 07:12 PM
|
#5 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
09-06-2007, 07:15 PM
|
#6 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by Wildhoney
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.
|
|
|
|
09-06-2007, 07:20 PM
|
#7 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
09-14-2007, 01:31 PM
|
#8 (permalink)
|
|
The Contributor
Join Date: Sep 2007
Posts: 41
Thanks: 0
|
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
|
|
|
12-05-2007, 05:13 PM
|
#9 (permalink)
|
|
The Wanderer
Join Date: Dec 2007
Location: The Netherlands
Posts: 13
Thanks: 3
|
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.
|
|
|
|
12-10-2007, 01:06 AM
|
#10 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Posts: 127
Thanks: 14
|
Seems like 5 lines of CSS to me. 
|
|
|
|
12-10-2007, 01:09 AM
|
#11 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
12-10-2007, 01:21 AM
|
#12 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Posts: 127
Thanks: 14
|
I'm just busting your balls.
|
|
|
|
12-10-2007, 07:39 AM
|
#13 (permalink)
|
|
The Contributor
Join Date: Dec 2007
Location: Belgium
Posts: 60
Thanks: 6
|
Quote:
Originally Posted by Wildhoney
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
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.
|
|
|
|
12-10-2007, 10:00 AM
|
#14 (permalink)
|
|
The Contributor
Join Date: Apr 2005
Location: Kent, UK
Posts: 54
Thanks: 0
|
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.)
|
|
|
|
12-15-2007, 04:38 AM
|
#15 (permalink)
|
|
The Wanderer
Join Date: Dec 2007
Location: Indianapolis, Indiana, USA
Posts: 16
Thanks: 0
|
Quote:
Originally Posted by Dr John
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.)
|
I have to agree with Dr. John.
Declaring your DOCTYPE will definitely help.
While each browser has it's issues, most try to follow the rules of the standard you declare. If you don't declare a DOCTYPE, then the browser has to guess which standard to follow or use a default standard. The problem is that all of the browsers have different systems in place for guessing the proper standard or use different default standard. So IE might default to HTML1.1 and FireFox might try to guess the best standard. Since the standards are so different, the same code is parsed differently. By declaring the DOCTYPE, the browsers should do a much better job of following the same rules. You'll still have some cross-compatibility issues but not nearly as many as you will if you don't declare your standard.
Give it a try sometime. Create an HTML/CSS document and don't declare a DOCTYPE. The use the exact same code and create a second file with the DOCTYPE declared. In almost every browser you use, you'll see a difference in the two documents even thought the HTML and CSS is the same. Go ahead and create three or four documents with the same content but declare a different DOCTYPE for each.
I'm really not a fan of using standards since no two browsers will follow all of the rules exactly the same way. Nonetheless, not specifying a standard will result in many more cross-compatibility issues than by specifying.
vujsa
__________________
Need PHP Help? - Handy PHP
|
|
|
|
12-10-2007, 10:43 AM
|
#16 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
12-10-2007, 11:01 AM
|
#17 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
And why is this a security fix? :| What can they do if I don't do that? 
|
|
|
|
12-10-2007, 01:51 PM
|
#18 (permalink)
|
|
The Contributor
Join Date: Apr 2005
Location: Kent, UK
Posts: 54
Thanks: 0
|
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.
|
|
|
|
12-10-2007, 10:23 PM
|
#19 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
12-10-2007, 10:34 PM
|
#20 (permalink)
|
|
The Contributor
Join Date: Apr 2005
Location: Kent, UK
Posts: 54
Thanks: 0
|
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.
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|