For example, the. html file code is as follows,
Reference content is as follows: <Html> <Head> <Title> center DIV </title> </Head> <Body> <Div id = "mainDiv> Center div </Div> </Body> </Html> |
The method for implementing the center CSS Code is the first method:
Reference content is as follows: Body { Text-align: center; Background-color: # ccc; Min-width: 780px; } # MainDiv { Width: 760px; Border: 1px solid white; Margin: 0 auto }
|
Type 2: the CSS Code implemented by the negative blank edge location method is
Reference content is as follows: Body { Text-align: center Background-color: # ccc; Min-width: 780px; } # MainDiv { Width: 760px; Margin-left:-pixel PX; Left: % 50; Positive: relative; Border: 1px solid white } |
Well, some people will ask why we should use the "min-width" attribute to define the minimum width of the body ?, The minimum width must be greater than or equal to the div width. If not, the page content may be squeezed out of the visible area of the browser. The specific reason is that this is a browser problem. Various browsers have slightly different support for CSS.