Home Web Front-end CSS Tutorial Introduction to multi-browser compatibility issues and solutions using CSS

Introduction to multi-browser compatibility issues and solutions using CSS

Mar 14, 2017 pm 04:16 PM

Compatibility processing points
1. DOCTYPE affects CSS processing

2. FF: After setting padding, the div will increase height and width, but IE does not, so you need to use !important to set an additional height and width

3. FF: supports !important, but IE ignores it. You can use !important to set a special style for FF

4. Vertical centering problem of div: vertical-align:middle; Increase the line spacing to the same height as the entire DIV line-height: 200px; Then insert the text and it will be vertically centered. The disadvantage is that the content must be controlled not to wrap.

5. The BOX model in mozilla firefox and IE is inconsistent in interpretation, resulting in a 2px difference. Solution:

div{margin :30px!important;margin:28px;}

Note that the order of these two margins must not be reversed, !important this attributeIE cannot recognize it, but other browsers can be identified. So it is actually interpreted like this under IE:

div{maring:30px;margin:28px}

If you repeat the definition, it will be executed according to the last one, so you cannot just write margin:XXpx!important ;

Browser differences
1. Indentation problem of ul and ol lists

When eliminating the indentation of ul, ol and other lists, the style should be written as: list-style:none;margin:0px;padding:0px;
The margin attribute is valid for IE, and the padding attribute is valid for FireFox.

[Note] It has been verified that in IE, setting margin:0px can remove the upper, lower, left and right indents, blanks, and list numbers or dots of the list. Setting padding has no effect on the style; in Firefox, setting margin :0px can only remove the top and bottom spaces. Setting padding:0px can only remove the left and right indents. You must also set list-style:none to remove list numbers or dots. In other words, in IE, only margin:0px can be set to achieve the final effect, while in Firefox, margin:0px, padding:0px and list-style:none must be set at the same time to achieve the final effect.

2. CSS transparency issue

IE: filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=60).
FF:opacity:0.6.
[Note] It is best to write both and put the opacity attribute below.

3. CSS rounded corners problem

IE: Versions below ie7 do not support rounded corners.
FF: -moz-border-radius:4px, or -moz-border-radius-topleft:4px;-moz- border - radius-topright:4px;-moz-border-radius-bottomleft:4px;-moz-border-radius-bottomright:4px;.
[Note] The rounded corner problem is a classic problem in CSS. It is recommended to use the JQueryframework set to set the rounded corners, leaving these complex issues to others to think about. However, jQuery's rounded corners only support the rounded corners of the entire area and do not support the rounded corners of the border. However, the rounded corners of this border can be achieved through some simple means. I will introduce it next time.

4. cursor:hand VS cursor:pointer

Problem description: Firefox does not support hand, but IE supports pointer, both are hand instructions.
Solution: Use pointer uniformly.

5. Different definitions of font size

The definition of font size small is different. It is 13px in Firefox and 16px in IE. The difference is quite big.

Solution: Use the specified font size such as 14px.

Between divs and divs of multiple elements (picturesor links) arranged side by side, spaces and carriage returns in the code will be ignored in Firefox, but will be displayed by default in IE is space (about 3px).

6. CSS double-line bump border
IE: border:2px outset;.
FF: -moz-border-top-colors: #d4d0c8 white;-moz-border-left-colors: #d4d0c8 white;-moz-border-right-colors:#404040 #808080;-moz-border- bottom-colors:#404040 #808080;

Browser bug
1. IE double margin bug

The margin set for a div set to float under IE will be doubled. This is a bug that exists in ie6.

Solution: Add display:inline; inside this div

For example:

<#div id="imfloat">

The corresponding css is

The following is the content of quote:

#IamFloat{ 
float:left; 
margin:5px;/*IE下理解为10px*/ 
display:inline;/*IE下再理解为5px*/ 
} 
#IamFloat{ 
float:left; 
margin:5px;/*IE下理解为10px*/ 
display:inline;/*IE下再理解为5px*/ 
}
Copy after login

There are too many problems in CSS, even the same CSS definition The display effects in different page standards are different. A suggestion that is in line with development is that the page should be written using standard XHTML standards, with less use of tables, and CSS definitions should be based on the standard DOM as much as possible, taking into account mainstream browsers such as IE, Firefox, and Opera. In many cases, the CSS interpretation standards of FF and Opera are closer to the CSS standards and more normative.

2. IE selector space BUG
Today when I was setting the first character style for the blog paragraph style, I discovered that a space can also invalidate the style.

Please look at the following code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="//www.w3.org/1999/xhtml"> 
<head> 
<title></title> 
<style type="text/css"> 
<!-- 
p{font-size:12px;} 
p:first-letter{font-size:300%} 
--> 
</style> 
</head> 
<body>
Copy after login

To the world, you are one person; but to someone, you are his entire world. Even if you are sad, don't frown, because you don't know who will fall in love with your smile.




[/code]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "//www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="//www.w3.org/1999/xhtml"> 
<head> 
<title></title> 
<style type="text/css"> 
<!-- 
p{font-size:12px;} 
p:first-letter{font-size:300%} 
--> 
</style> 
</head> 
<body> 

对于世界而言,你是一个人;但是对于某个人,你是他的整个世界。纵然伤心,也不要愁眉不展,因为你不知是谁会爱上你的笑容。

Copy after login

This code defines the first character style of

in IE6 It seems to have no effect (IE7 has not been tested), and after adding a space to p:first-letter and {font-size:300%}, that is, p:first-letter {font-size:300%}, it is displayed It's normal. But the same code looks normal under FireFox. Logically speaking, the way of writing p:first-letter{font-size:300%} is correct. So what's the problem? The answer is the hyphen "-" in pseudo-class . There is a BUG in IE. When processing pseudo-classes, if the name of the pseudo-class contains a hyphen "-", the name of the pseudo-class must be followed by a space, otherwise the style definition will be invalid. In FF, it can be processed normally with or without spaces.

The above is the detailed content of Introduction to multi-browser compatibility issues and solutions using CSS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Building an Ethereum app using Redwood.js and Fauna Building an Ethereum app using Redwood.js and Fauna Mar 28, 2025 am 09:18 AM

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

See all articles