Div box model (Figure 1), div Box Model

Source: Internet
Author: User

Div box model (Figure 1), div Box Model

 

OffsetLeft obtains the left margin relative to the parent object.

Left gets or sets the left margin relative to the parent object with the position attribute (position defined as relative ).

If the position of the parent div is defined as relative and the position of the child div is defined as absolute, the style. left value of the Child div is relative to the parent div value,
This is the same as offsetLeft. The difference is:
1. style. left returns a string, such as 28px, and offsetLeft returns a value of 28. If you need to calculate the obtained value,
It is also convenient to use offsetLeft.
2. style. left is read/write, and offsetLeft is read-only. To change the position of the div, you can only modify style. left.
3. The value of style. left must be defined in advance. Otherwise, the obtained value is null. And must be defined in html. I have tried it. If it is defined in
In css, the value of style. left is still empty, which is the problem I encountered at the beginning. The value of style. left is always not available.

OffsetLeft can still be obtained without the need to define the position of the div in advance.

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.