Today I wrote a div, using margin:0 auto; to define its attributes and center it, but it turned out to be invalid.
At first, I thought it was a code conflict in the css. I checked it several times and found that there was no problem. Then I tested it with Firefox and Google Chrome and found that it was centered. . .
It seems to be a browser compatibility issue. I suddenly remembered that I am using win7 and ie has been upgraded to ie8. It seems that the problem is the compatibility of ie8. Baidu. . . .
The solution is copied below:
To achieve centering under IE6, 7, and Firefox, margin: auto is generally used to achieve it, but under IE8, this is not enough. Two solutions are provided:
Method 1 (recommended):
First, the document type must be set at the top of the page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transition al.dtd">
and add:
in the head<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/> 即可!
Method 2:
Body settings {text-align:center;width:100%;}
Include all divs in
#wrap { text-align:left; width:***; margin:0 auto; }
and add in the head:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
That’s it!
Method three:
Use
The above is the detailed content of css:margin:0 auto can't be centered in ie8. For more information, please follow other related articles on the PHP Chinese website!

In a perfect world, our projects would have unlimited resources and time. Our teams would begin coding with well thought out and highly refined UX designs.

Oh, the Many Ways to Make Triangular Breadcrumb Ribbons

SVG has its own set of elements, attributes and properties to the extent that inline SVG code can get long and complex. By leveraging CSS and some of the forthcoming features of the SVG 2 specification, we can reduce that code for cleaner markup.

You might not know this, but JavaScript has stealthily accumulated quite a number of observers in recent times, and Intersection Observer is a part of that

We may not need to throw out all CSS animations. Remember, it’s prefers-reduced-motion, not prefers-no-motion.

PWA (Progressive Web Apps) have been with us for some time now. Yet, each time I try explaining it to clients, the same question pops up: "Will my users be

It's extremely surprising to me that HTML has never had any way to include other HTML files within it. Nor does there seem to be anything on the horizon that

There are a lot of different ways to use SVG. Depending on which way, the tactic for recoloring that SVG in different states or conditions — :hover,


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

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.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools