Css vertical center sorting, css vertical center sorting

Source: Internet
Author: User

Css vertical center sorting, css vertical center sorting
This is my understanding and arrangement after learning. If you have any errors or questions, please correct them and I will keep updating them!

There are many vertical centers and solutions.

Known element widthPosition + negative margin value can be used

Absolute positioning + 4 directions all 0px + margin: auto can achieve horizontal vertical center based on the parent container. If you only need vertical center, you can delete left and right, there are also many ways to align horizontally
Absolute Position + Left 50% + margin left: negative value in half width can be horizontally centered or right
Absolute positioning + upper 50% + margin: The negative value of half of the height can be vertical center or bottom

<! DOCTYPE html> View Code

 

Unknown element widthYou can use position positioning + transform: translate (x, y) to move
Absolute positioning + upper 50% + lower 50% + transform: translate (-50%,-50%) can be vertically centered

<! DOCTYPE html> View Code

 

Vertical center of img image in div:

Vertical-align: middle can be used, but this attribute only works for elements of the inline-block type (inline also affects). I have to continue learning about vertical-align, thank you for your correction.


Method 1: Image vertical-align: the height of the middle + parent element is consistent with the line-height.

<! DOCTYPE html> View Code

Method 2: Set the parent element to display: table-cell and vertical-align.

<! DOCTYPE html> View Code

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.