Correct use of margin: 0 auto and body {text-align: center;} to implement element center (convert) and margintext-align
What are the similarities and differences between body {text-align: center} and margin: 0 auto?
Text-align is used to set or align the text in an object. T
Margin: 0 auto and text-align: Difference Between center (reprinted), margintext-align
From: http://www.cnblogs.com/zhwl/p/3529473.html
Basic concepts:
1. text-align: attribute specifies the horizontal alignment of text in the element;
This attribute sets the horizontal alignment of text in block-level elements by specifying the point to which the row box is aligned;
This attribute is generally used when te
centering, which is the same vertically), it needs to coincide with its midline (the gray dashed line) and the parent element's midline (the Blue dashed line), and when we let an element be absolutely positioned, and the left value is set to 50%, The leftmost side of this element is always aligned with the midline of the parent element (the blue dashed line), and what we have to do is let it move back to the left part on this basis, how much is this part? As you can see from the diagram, the me
Recently in doing a news site, because the data collected, the picture is not centered, resulting in a very ugly interface, so the need to globally define the output of the film Center. . content img { max-width:800px;_width:expression (This.width > 800?) "800px": this.width); Control the overall size of the picture Clear:both; Display:block; Margin:auto; }Test Address: http://baijia.xuetong365.com/show-36814.htmlCSS Globa
Many beginners to make Web pages of friends, may encounter a common problem, is to add margin:0 Auto in CSS, but no effect, can not center the issue, margin:0 auto; The meaning is: the upper and lower boundary is 0, the left and right according to the width of the self-adaptation, in fact, the meaning of the horizontal center
1 Div in the center of the page problem1) when theposition value is relative (relative positioning), the CSS settings property margin:0 Auto; (0 auto, which indicates that the upper and lower bounds are 0, the left and right are adaptive to the same value according to the width, that is, centered).2)position value is relative (absolute positioning), CSS settings
Personal EssaysThe code implements the following functions:1, loading the network unknown size of the picture, the user can freely enter the size of the display area, the picture will automatically adapt to the wide height.2, horizontal, vertical center image of unknown size1 DOCTYPE HTML>2 HTMLLang= "en">3 Head>4 MetaCharSet= "UTF-8">5 title>Horizontally and vertically centers an unknown size picturetitle>6 style>7 #imageBox{8 width:250px
In general, you can use CSS style: margin: 0 auto; or margin: 0 auto 1px; to center the DIV, but sometimes use margin: 0 auto can be centered in browsers such as firef and chrome, but not in ie678.The following code:Solution 1You can center the That is:Solution 2In fact, it
Tags: HTTP Io ar OS Div on code BSThe code is shot, and it is good to use the shoes in a hurry:Div {Width: 1000px; Height: 500px;Position: absolute; left: 0; top: 0; Right: 0; bottom: 0;Margin: auto;/* focus on auto */}The method used by the blogger is also good, but JQ needs to be used to obtain the length and width of the container without knowing the length and width of the iner. In this case, the first
margin:0px Auto Not centered problem is really annoying, what good way to solve it? Here is a detailed introduction, there is a need for friends can refer to, I hope to help you
In general, when you center the Div, use CSS:
Copy Code code as follows:
DivX {margin:0 auto;}
This CSS in Firefox is good, but in IE does not work, the Internet to see the follow
IE8 is no longer useful to margin: 0 auto; this CSS does not seem to be useful, and the page cannot be centered. I will come back in the afternoon to see how to center it. The front-end of the Pacific also said that their company ignored the existence of IE8, test or previous version.
The reason is found. I wrote the margin: 0 auto; in the body tag. IE7 and lower
Copy codeThe Code is as follows:Note: 1. The following testCss1 and testCss2 styles are the same as testCss. Only the size is set.2. the height and width of the red part must be defined, which is the height and width of the parent layer container that stores the img.3. text-algin: horizontally centered4. display: block, which must be set. Otherwise, enabling auto scaling under FF does not work.Usage: 1. Define the style at the parent layer of img, inc
CopyCode The Code is as follows:
Note: 1. The following testcss1 and testcss2 styles are the same as testcss. Only the size is set.2. the height and width of the red part must be defined, which is the height and width of the parent layer container that stores the IMG.3. Text-algin: horizontally centered4. display: block, which must be set. Otherwise, enabling auto scaling under FF does not work.
Usage: 1. Define the style at the parent layer
I haven't kept a diary for a long time. In the final analysis, I haven't learned for a long time. I 've been working and using margin for a long time. I 've been depressed for a long time. I 've read a lot of questions and answers online, finally, let's take an example and study it. In fact, div center is not that difficult!
CopyCodeGo to notepad and change it to an HTML suffix.
Code
Code highlighting produced by Actipro CodeHighlighter (freew
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.