Vertical center of DIV content, vertical center of div

Source: Internet
Author: User

Vertical center of DIV content, vertical center of div

Vertical-align: middle does not work on div. For example:

1 <! DOCTYPE html> 2 

After running, the button is not vertically centered in the DIV:

Solution: If the width and height of the div and button are determined to be specific pixel values, you can directly set the css attribute of the button: position: relative; top (div. height-button. height)/2, left is (div. width-button.height)/2; otherwise add a div parent element to the button, the width and height are the same as the button, position is set to relative, both top and left are 50% (that is, the position in the upper left corner is set in the center of the outer div), and then the coordinates in the upper left corner of the button are set to-50% of the parent element div width and height (that is, the width and height of the button itself ).

The Code is as follows:

1 <! DOCTYPE html> 2 

After re-running, the buttons in the div are displayed in the center

END

Related Article

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.