1. Use Inline-block and vertical-align to achieve centering : This method is suitable for the case of unknown width height.
Reference: https://css-tricks.com/centering-in-the-unknown/2. Use relative absolute positioning and negative margins to center up or down : height and width known
In fact, the second to understand can not, first relative to the parent element top,left positioning in 50% position, this is just the top left corner of the image
-style:solid; Display:inline;}BodyDivclass= "Container"> ul> Li>ahref="#">1a>Li> Li>ahref="#">2a>Li> Li>ahref="#">3a>Li> ul>Div>The effect:2, the following uses the parent element floating and relative positioning as well as lelf:50%. Child elements are still set but left:-50%.Corrected CSS code:. container ul{ list-style:none; Float:left; position:relative;left:50%; padding:0;}. Container li{ margin-right:
1. Absolute centering (Absolute centering) technologyWe often use margin:0 auto, to achieve horizontal center, and always think Margin:auto; not vertical center ... In fact, implementing vertical centering requires only declaring the element height and the following CSS:. absolute-center { margin:auto; Position:absolute; Left: 0; right:0; Top: 0; bottom:0;}Advantages:1. Support cross-browse
vertically, but the picture here is Position:absolute, and it's easy to think about setting up Margin:auto;padding:auto; You can center the picture that is out of the document stream vertically. See absolute horizontal and Vertical centering in CSS.
However, this method is not valid for IE7. So there's only a layer of div outside the picture.
This cock is a very common way to center vertically.
you've seen the Inline-block I wrote before, replace float may be clear about the benefits of this property
The code is as follows
Copy Code
Fourth type
The code is as follows
Copy Code
Disadvantage is incompatible ie6,ie7
It is recommended to use Inline-block, a horizontally centered method that preserves block-level element characteristics and is perfectly compatible. is a bit more code. Alternatively, you can use
Source: http://www.imooc.com/code/6365In addition to inserting the table label in the first two sections and changing the display type of the element, you can center the indeterminate-width block element Horizontally, this section describes the 3 ways to achieve this effect, set the float and relative positioning to achieve. Method Three: By setting float to the parent element and then setting position:relative and left:50% for the parent element , the child elements are set position:relative an
-center { width: 50px; height: 50px; margin: calc (50%-25px)/* because the percent value of margin is calculated relative to the width of the parent element, Therefore the method only applies to the parent container with the same width and height */}
Four, Flex
Block elements and floating elements. Block { display: flex; min-height50vh; } . Block-center{ marginauto; }
inline element (add to outer parent element). Inline { display: flex; m
relative to itself, because the child element is already set to absolute, so if you use relative, you need to add a layer [Note] This method is fully compatible, but adds HTML structureDivclass= "Parent"style= "background-color:gray;height:20px;"> Divclass= "Childwrap"> Divclass= "Child"style= "Background-color:lightblue;">DEMODiv> Div> Div>"3" with negative marginThe margin percentage is relative to the containing block, so you need to add a layer of [Note] Although fully compatible, i
CSS vertical horizontal center-feishuang008 small summary: text-align: center is used for horizontal center of elements in the row; margin-left: auto is used for horizontal center of block-level elements; margin-right: auto;
First, we will discuss the situation of a single row.
There is no doubt that this is the sim
>这是放在span中的文字,通过外层div设置display: table-cell以及vertical-align: middle实现垂直居中。span>div>:When we remove the vertical-align:middle of span, this is the case:See any differences? The line spacing of the text is even smaller. If you run the code on your computer, you'll find that the lines are in the middle and not moving up like a picture. I'm also trying to figure out what's going on, and if you know why, please tell me.Method Two: Elastic box methodCSS code:.container{width: 300px; height: 200px
How does css implement horizontal center of span in div and center of cssspandiv?
How does css implement horizontal center of span in div:This topic describes how to set a span to horizontally center in the div. The following code example describes how to achieve this effect.Many friends may think that using margin: 0p
This blog post mainly records a variety of ways to achieve horizontal centering, as well as their advantages and disadvantages.The sub-element div is centered horizontally in the parent element div1. Use Inline-block and text-align: DOCTYPE HTML>HTML>Head> title>Asdtitle> styletype= "Text/css">. Parent{Height:200px;Background-color:Black;text-align:Center; }. Child{Height:150px;width:600px;Bac
;left:-50%; }
The effect is the same, it does not map . (First, the UL set left float is to make the UL width is not 100%, but a few Li width sum.) After the UL relative positioning use left to move the UL to the play position. Because the relative positioning is the original position of the original point, so the overall movement of the middle, this way the left side of the element is the centerline, so long as the left:-50% or right:50% is centered)
The above
The horizontal center of the page is usually a headache, especially for beginners. Incompatibilities between browsers can also pose a big problem. Here's a look at the common page horizontal centering method.
See the "Mastering CSS" section below.
HTML code:
The code is as follows
IE will mistakenly think of Text-align:center as having everything centered, n
text," The use of blank images to achieve vertical alignment success, so I also according to their own ideas to try, the effect and his identical, and compatible with the browser, The code is much simpler than the first method, the main thing is not to write the effect of IE alone, and easy to understand, let's look at this method below.HTML Markup class= "Imgwrap clearfix" > class= "Imgbox" >class=" Imgbox ">class= "Imgbox" >class= "Imgbox" >
How does css implement vertical and horizontal center of images in an unknown wide-height div? cssdiv
How does css implement vertical horizontal center of images in an unknown wide-height div:In some cases, we may want to align an image vertically and horizontally in the div, but sometimes the size of the div is the p
Vertical-align is a good attribute, but this attribute is initially for the cell of the table. Of course, although this attribute does not work for block-level elements, it still works for row elements such as span (at this time, when this attribute is set to a negative value, the content of the element is moved down, while the positive value is moved up ).The following is a professional vertical center centralized solution. This is recorded for reference.1. Center a single row verticallyThe ver
Front-End Notes: Draw a horizontal line in HTML and a CSS file that can be referenced by IE10,
First of all, happy National Day ~~~ This is my first national day outside the province. After all, I graduated this year ~~~
Recently, I will continue to summarize the front-end knowledge used in the previous WEB project and share it with you ~~~
How can we draw a horizontal
This is my interview in a company encountered problems, then did not answer!!So see the small partners must pay attention to!!Change the browser width to see the effect:Right and left.Then we'll look at the code:First method: (floating)styletype= "Text/css">. Left,.right,.center{Border:1px solid;Height:100px;text-align:Center;Line-height:100px;font-size:50px; }. Left{float: Left;width:100px; }. Right{float: Right;width:100px; }. C
its elementsYou can set the height and margin of a block elementIf you do not set the width yourself, its width is the width of its parent elementBlock elements can accommodate block elements and inline elements, but cannot contain block elements in inline elements3. Several centering methods(1) Set text in block element to center horizontallyUse the Text-align style to set the text or picture centered on the block.The style can only manipulate block elements or inline elements that are display
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.