search
HomeWeb Front-endHTML TutorialIE6, IE7, FF | Comprehensive solution to CSS DIV compatibility issues CSS HACK_html/css_WEB-ITnose

Copyright statement: When reprinting, please indicate the original source and author information of the article and this statement in the form of a hyperlink
http://monw3c.blogbus.com/logs/12837657.html

1. CSS HACK
The following two methods can solve almost all HACKs today.

1. !important

With IE7’s support for !important Supported, the !important method is now only for IE6 HACK. (Pay attention to the writing. Remember that the declaration position needs to be in advance.)

2. IE6/IE77 vs. FireFox

*html and *html are IE-specific tags, which are not supported by firefox. And *html is a IE7-specific tag.

Note:
* html HACK for IE7 must ensure the following statement at the top of the HTML:
"http://www.w3.org/TR/html4/loose.dtd">

2. Universal float closure (very important!)

For the principle of clear float, please refer to [How To Clear Floats Without Structural Markup]
Add the following code to Global CSS and add class="clearfix" to the div that needs to be closed. It works every time.

.clearfix:after
{
content:".";
display:block;
height:0;
clear:both;
visibility:hidden;
}
.clearfix
{
display:inline-block;
}
/ * Hide from IE Mac */
.clearfix {display:block;}
/* End hide from IE Mac */
/* end of clearfix */



1, !important

With IE7’s support for !important, the !important method is now only for IE6’s HACK. (Pay attention to the writing. Remember that the declaration position needs to be in advance.)



2, IE6/IE77 vs. FireFox

* html and *html are IE-specific tags, which firefox does not support yet. And *html is a IE7-specific tag.



Note:
* html HACK for IE7 must ensure the following statement at the top of the HTML:


2. Universal float closure (very important!)

For the principle of clear float, please refer to [How To Clear Floats Without Structural Markup]
Add the following code to Global CSS and add class="clearfix" to the div that needs to be closed. It works every time.


3. Other compatibility tips (again? Whoops)

1. Setting padding on a div under FF will cause the width and height to increase, but IE will not. (can be solved with !important)
2, centering problem.
1). Vertically centered. Set line-height to the same height as the current div, and then pass vertical-align: middle. (Be careful not to wrap the content.)
2). Horizontally Centered. margin: 0 auto; (of course not universal)
3, if you need to add styles to the content in the a tag, you need to set display: block; (common in navigation tags)
4, FF and IE for BOX The difference in understanding leads to the 2px difference and other issues such as the margin of a div set to float doubling under IE.
5. The ul tag has list-style and padding by default under FF. It is best to declare it in advance to avoid unnecessary Trouble. (Common in navigation tags and content lists)
6. Don’t fix the height of the div as an external wrapper. It is best to add overflow: hidden. to achieve height adaptability.
7. Regarding the hand cursor. cursor: pointer. And hand is only applicable to IE.

1 CSS styles for firefox ie6 and ie7
Now most of them use !important to hack, and the ie6 and firefox tests can display normally,
But ie7 can interpret !important correctly, which will cause the page not to be displayed as required! Find a pin
A good hack for IE7 is to use "*html". Now browse it with IE7 and there should be no problem.
Now write a CSS like this:

#1 { color: #333; } /* Moz */
* html #1 { color: #666; } /* IE6 */
* html #1 { color: #999; } /* IE7 */
Then the font color is displayed as #333 under firefox, #666 under IE6, and #999 under IE7.

2 Centering issues in css layout
The main style definitions are as follows:

body {TEXT-ALIGN: center;}
#center { MARGIN-RIGHT: auto; MARGIN -LEFT: auto; }
Explanation:
First define TEXT-ALIGN: center in the parent element; this means that the content in the parent element is centered; for IE, this setting is enough.
But it cannot be centered in mozilla. The solution is to add "MARGIN-RIGHT: auto;MARGIN-LEFT: auto;" when defining the child element.
It should be noted that if you want to use this method to center the entire page, it is recommended not to Set in a DIV, you can split multiple divs in sequence.
Just define MARGIN-RIGHT: auto;MARGIN-LEFT: auto; in each split div.

3 different interpretations of the box model.

#box{ width:600px; //for ie6.0- width:500px; //for ff ie6.0}
#box{ width:600px!important //for ff width:600px; //for ff ie6.0 width /**/:500px; //for ie6.0-}

4 Double distance generated by floating ie

#box{ float:left; width:100px; margin:0 0 0 100px; //In this case, IE will generate a distance of 200px display:inline; //Ignore the float}
Let’s talk about the two elements block and inline in detail. The characteristics of the Block element are: it always starts on a new line, and the height, width, line height, and margins can all be controlled (block elements); the characteristics of the Inline element are: and other Elements are on the same line,... cannot be controlled (inline elements);

#box{ display:block; //You can simulate inline elements as block elements display:inline; //Achieve the same line The effect of arrangement diplay:table;

5 Problems with IE and width and height

IE does not recognize the definition of min-, but in fact it treats normal width and height as having min situation. This will cause a big problem. If you only use width and height,
these two values ​​​​will not change in a normal browser. If you only use min-width and min-height, it is equivalent to not setting the width and height under IE. high.
For example, if you want to set a background image, this width is more important. To solve this problem, you can do this:
#box{ width: 80px; height: 35px;}html>body #box{ width: auto; height: auto; min-width: 80px; min-height: 35px;}

6 Minimum width of the page

min-width is a very convenient CSS command. It can specify that the minimum width of an element cannot be smaller than a certain width, so that the layout can always be correct. But IE doesn't recognize this,
and it actually treats width as the minimum width. In order to make this command also work on IE, you can put a

under the tag, and then specify a class for the div:
Then the CSS is designed like this:
#container{ min-width: 600px; width:expression(document.body.clientWidth The first min-width is Normal; but the width in line 2 uses Javascript, which is only recognized by IE, which will also make your HTML document less formal. It actually implements the minimum width through Javascript judgment.

7 Clear floats

.hackbox{ display:table; //Display the object as a block element-level table} or .hackbox{ clear:both;}
Or add: after (Pseudo object), sets the content that occurs after the object, usually used in conjunction with content. IE does not support this pseudo object, and non-Ie browsers support it.
So it does not affect IE/WIN browsers. The most troublesome thing about this...#box:after{ content: "."; display: block; height: 0; clear: both; visibility: hidden;}

8 DIV floating IE The text generates a 3-pixel bug

The left object floats, and the right side is positioned using the left margin of the outer patch. The text within the right object will have a 3px spacing from the left.

#box{ float :left; width:800px;}#left{ float:left; width:50%;}#right{ width:50%;}*html #left{ margin-right:-3px; //This sentence is the key}
HTML code

9 attribute selector (this is not compatible, it is a bug in hiding css)

p[id]{}div[id]{}
This is for IE6.0 and versions below are hidden. The functions of FF and OPera
There is still a difference between attribute selector and sub-selector. The scope of sub-selector is narrowed in form, while the scope of attribute selector is relatively large. , such as p[id], all p tags with ids are of the same style.

10 IE hide-and-seek problem

When the div application is complex, there are Some links, DIVs, etc. are prone to hide-and-seek problems at this time.
Some content cannot be displayed. When the mouse selects this area, it is found that the content is indeed on the page.
Solution: Use line-height attribute for #layout or use fixed height and width for #layout. Keep the page structure as simple as possible.

11 Height non-adaptation

Height non-adaptation means that when the height of the inner layer object changes, the height of the outer layer cannot be automatically adjusted, especially when the inner layer object uses
margin or paddign hour.
Example:


Content in p object


CSS: #box {background-color:#eee; }
#box p {margin-top: 20px; margin-bottom: 20px; text-align:center; }
Solution: Add 2 empty div objects above and below the P object. CSS code: .1{height:0px;overflow: hidden;} Or add the border attribute to the DIV.
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
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?Mar 04, 2025 pm 12:32 PM

The official account web page update cache, this thing is simple and simple, and it is complicated enough to drink a pot of it. You worked hard to update the official account article, but the user still opened the old version. Who can bear the taste? In this article, let’s take a look at the twists and turns behind this and how to solve this problem gracefully. After reading it, you can easily deal with various caching problems, allowing your users to always experience the freshest content. Let’s talk about the basics first. To put it bluntly, in order to improve access speed, the browser or server stores some static resources (such as pictures, CSS, JS) or page content. Next time you access it, you can directly retrieve it from the cache without having to download it again, and it is naturally fast. But this thing is also a double-edged sword. The new version is online,

How do I use HTML5 form validation attributes to validate user input?How do I use HTML5 form validation attributes to validate user input?Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

How to efficiently add stroke effects to PNG images on web pages?How to efficiently add stroke effects to PNG images on web pages?Mar 04, 2025 pm 02:39 PM

This article demonstrates efficient PNG border addition to webpages using CSS. It argues that CSS offers superior performance compared to JavaScript or libraries, detailing how to adjust border width, style, and color for subtle or prominent effect

What are the best practices for cross-browser compatibility in HTML5?What are the best practices for cross-browser compatibility in HTML5?Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <datalist> element?What is the purpose of the <datalist> element?Mar 21, 2025 pm 12:33 PM

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What is the purpose of the <meter> element?What is the purpose of the <meter> element?Mar 21, 2025 pm 12:35 PM

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

How do I use the HTML5 <time> element to represent dates and times semantically?How do I use the HTML5 <time> element to represent dates and times semantically?Mar 12, 2025 pm 04:05 PM

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

What is the purpose of the <progress> element?What is the purpose of the <progress> element?Mar 21, 2025 pm 12:34 PM

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

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)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

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 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)