search
HomeWeb Front-endHTML TutorialBrowser compatibility issues during div css layout_html/css_WEB-ITnose

As the market share of Firefox increases, IE declines, especially in Europe, where Firefox has a higher market share. Without a unified Under the standard, browser compatibility issues have become more and more important. Sometimes it looks fine under IE, but it is completely different in Firefox or other browsers. At that time, I feel very unhappy and frustrated!

The most commonly used method when distinguishing between Firefox and IE is the !important method. For compatibility issues with different browsers and different versions of the browser, there are also the following methods, such as: @import, comments, attribute selectors, sub- Methods such as object selector and voice-family are described in "Css Website Layout Record".

The following are the CSS compatibility issues of IE and Firefox

1. DOCTYPE affects CSS Processing

2.FF: When the div is set to margin-left and margin-right to auto, it is already centered, but IE does not work

3.FF: When the body is set to text-align, the div needs to set margin: auto (mainly margin-left, margin-right) can be centered

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

5.FF: supports !important, IE ignores it, you can use !important to set a special style for FF. It is worth noting that the xxxx !important sentence must be placed above another sentence

6.div’s vertical centering problem: vertical-align:middle; Increase the line spacing to the same height as the entire DIV, line-height:200px; and then insert text, and it will be vertically centered. The disadvantage is that the content must be controlled without wrapping

7.cursor: pointer can display the cursor finger shape in IE FF at the same time, hand can only be used by IE

8.FF: link with border and background color, You need to set display: block and float: left to ensure no line breaks. Referring to menubar, setting the height of a and menubar is to avoid dislocation of the bottom edge display. If height is not set, a space can be inserted in menubar.

9. The BOX model interpretation in mozilla firefox and IE is inconsistent, resulting in a difference of 2px. Solution: div{margin:30px!important;margin:28px;}
Note that the order of these two margins must not be Wrote it backwards, according to Ajie, the !important attribute cannot be recognized by IE, but other browsers can. So it is actually interpreted like this under IE: div{maring:30px;margin:28px}
If the definition is repeated, the last one will be executed, so you cannot just write margin:XXpx!important;

10. The BOX interpretation of IE5 and IE6 is inconsistent
Under IE5 div{width:300px;margin:0 10px 0 10px;}
The width of the div will be interpreted as 300px-10px (right padding)-10px (left padding) finally The width of the div is 280px, but on IE6 and other browsers, the width is calculated as 300px 10px (right padding) 10px (left padding) = 320px. At this time we can make the following changes to div{width:300px! important;width /**/:340px;margin:0 10px 0 10px}
About this/**/. I don’t quite understand what it is. I only know that IE5 and firefox support it but IE6 does not. If anyone understands it, please Tell me, thanks! :)

11.ul tag has padding value by default in Mozilla, but in IE only margin has value, so first define ul{margin:0;padding:0;}
to solve the problem Most of the problems

 
Notes:

1. The float div must be closed.

For example: (where the attributes of floatA and floatB have been set to float:left;)


The NOTfloatC here does not want to continue to pan, but wants to be arranged downwards.
This code has no problem in IE, the problem lies in FF. The reason is that NOTfloatC is not a float label, and the float label must be closed.
Add
between

This div must pay attention to the declaration position and must be placed in the most appropriate place. It must be at the same level as the two divs with float attributes. There cannot be a nested relationship between them, otherwise an exception will occur.
And define the clear style as follows: .clear{
clear:both;}

In addition, in order to allow the height to automatically adapt, add overflow in the wrapper: hidden;
When a box contains a float, automatic height adaptation is invalid under IE. At this time, the layout private attribute of IE should be triggered (the evil IE!) You can use zoom:1; to achieve this. compatible.
For example, a wrapper is defined as follows: .colwrapper{
overflow:hidden;
zoom:1;
margin:5px auto;}

2. The problem of doubling margin.

The margin set for a div set to float under IE will be doubled. This is a bug that exists in ie6.
The solution is to add display:inline;
to this div. For example:

The corresponding css is
#IamFloat {
float:left;
margin:5px;/*under IE, it is understood as 10px*/
display:inline;/*under IE, it is understood as 5px*/}

3. About the inclusive relationship of containers

Many times, especially when there is a parallel layout in the container, such as two or three float divs, the width is prone to problems. In IE, the width of the outer layer will be squeezed by the wider inner div. Be sure to use Photoshop or Firework to measure with pixel-level accuracy.

4. Questions about height

If content is added dynamically, it is best not to define the height. Browsers can automatically scale, but if it is static content, it is best to set the height. (It seems that sometimes it won’t open automatically, I don’t know what’s going on)

5. The most ruthless method - !important;

If there is really no way to solve some detailed problems, You can use this method. FF will automatically parse "!important" first, but IE will ignore it. As follows.tabd1{
background:url(/res/images/up/tab1.gif) no-repeat 0px 0px! important; /*Style for FF*/
background:url(/res/images/up/tab1.gif) no-repeat 1px 0px; /* Style for IE */}
It is worth noting that, must Place the xxxx !important sentence above another sentence. As mentioned above

IE7.0 is out, and there are new problems with CSS support. There are more browsers, and the compatibility of web pages is getting worse. We are still struggling. To solve the compatibility problem of IE7.0, I found the following article:

Now I mostly use !important Hack, for IE6 and Firefox tests, it can be displayed normally, but IE7 can correctly interpret !important, which will cause the page not to be displayed as required! After searching, I found a good hack for IE7 which is to use "* html". Now browse it with IE7 and there should be no problem.

Now write a CSS like this:
#example { color: #333; } /* Moz */
* html #example { color: #666; } /* IE6 */
* html #example { color: #999; } /* IE7 */

Then the font color under firefox is displayed as #333, the font color under IE6 is displayed as #666, and the font color under IE7 is displayed as #999, they don't interfere with each other. I really hope that crappy IE6 is retired soon. . . .

Statement
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
From Text to Websites: The Power of HTMLFrom Text to Websites: The Power of HTMLApr 13, 2025 am 12:07 AM

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.

Understanding HTML, CSS, and JavaScript: A Beginner's GuideUnderstanding HTML, CSS, and JavaScript: A Beginner's GuideApr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Role of HTML: Structuring Web ContentThe Role of HTML: Structuring Web ContentApr 11, 2025 am 12:12 AM

The role of HTML is to define the structure and content of a web page through tags and attributes. 1. HTML organizes content through tags such as , making it easy to read and understand. 2. Use semantic tags such as, etc. to enhance accessibility and SEO. 3. Optimizing HTML code can improve web page loading speed and user experience.

HTML and Code: A Closer Look at the TerminologyHTML and Code: A Closer Look at the TerminologyApr 10, 2025 am 09:28 AM

HTMLisaspecifictypeofcodefocusedonstructuringwebcontent,while"code"broadlyincludeslanguageslikeJavaScriptandPythonforfunctionality.1)HTMLdefineswebpagestructureusingtags.2)"Code"encompassesawiderrangeoflanguagesforlogicandinteract

HTML, CSS, and JavaScript: Essential Tools for Web DevelopersHTML, CSS, and JavaScript: Essential Tools for Web DevelopersApr 09, 2025 am 12:12 AM

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesThe Roles of HTML, CSS, and JavaScript: Core ResponsibilitiesApr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

Is HTML easy to learn for beginners?Is HTML easy to learn for beginners?Apr 07, 2025 am 12:11 AM

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

What is an example of a starting tag in HTML?What is an example of a starting tag in HTML?Apr 06, 2025 am 12:04 AM

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools