CSS----Layout FAQs

Source: Internet
Author: User

1. A div with a width height of 50px, how to achieve the vertical center left and right?

Realize the idea: first give Div set position:absolute, achieve absolute positioning, then set top and left value are 50%; so the div is in the middle of the approximate position, here said roughly, This is because the div is shifted 0.5 times times the height and width, respectively, down to the right. Then set Margin-left:-() width;margin-top:-() height is ok (*^__^*)

. tocenter{Position:absolute; Width:50px;height:50px;background: #0066D5;               margin-left:-25px; margin-top:-25px;top:50%;left:50%; 

Extension: What if the implementation div1 is centered in the div2 (outer div)?

Realize the idea: well ... This time just add position:relative to Div2.

2.

  

CSS----Layout FAQs

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.