Questions about the margin top percent value

Source: Internet
Author: User

Don't want to say how bad mood today!

More than 9 start to find a "bug", the requirement is to adjust the position of a div dynamically depending on the height of the screen, the code is probably the case.

 <div  style=   "margin-top:25%;   margin-left:25%;   width:50px;   height:50p;   Background-color:yellow; " >  </DIV>  



Demonstrate:


then I found, "when the width of the window changes, margin-top change, change!" !!! , adjusted a night, asked a lot of front-end group, paste the code, unexpectedly no one knows why!!!

Finally find a sentence:

' Margin-top ', ' Margin-bottom '
Percentages:refer to width of containing block

Yes, that's right, Margin-top is set as a percentage, only with the parent container width!!! Width!!! Who can tell me why is the width!!! Deeply moved by his ignorance. Well! Come on!

Questions about margin top percent value

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.