This article will separately discuss the usage of div horizontal center in css tutorials, and the compatibility issues in ie, ie7, and firefox.
Center horizontally (centering)
This is a simple technique, but it is worth repeating it again, because I have seen many new users asking this question: How to center css horizontally? You need to define the width of the element and define the horizontal margin. If your layout is contained in a layer (container), you can define it to center horizontally:
# Wrap {
Width: 760px;/* change to the width of your layer */
Margin: 0 auto;
}
However, ie5/win cannot correctly display this definition. We use a very useful technique to solve this problem: use the text-align attribute, just like this:
Body {
Text-align: center;
}
# Wrap {
Width: 760px;/* change to the width of your layer */
Margin: 0 auto;
Text-align: left;
}
Text-align: center of the first body. The rule defines that all the elements of the body in ie5/win are centered (other browsers only center the text), and the second text-align: left; is to place the text in # warp to the left.