About how to maintain the same height of the two divs (solved by js)

Source: Internet
Author: User
I recently modified some previously written code and found some problems. For example, the two divs must dynamically maintain the same height. Original practice: divstyleoverflow: hiddendividleftstylemargin-bottom:-pixel PX; padding-bottom: pixel PX; divdividrightstylemargin-bottom:-pixel PX; padding-B

I recently modified some previously written code and found some problems. For example, two p must dynamically maintain the same height. The original practice was: p style = overflow: hidden p id = left style = margin-bottom:-pixel PX; padding-bottom: pixel PX; /p id = right style = margin-bottom:-adjust PX; padding-B

I recently modified some previously written code and found some problems.

For example, two p must dynamically maintain the same height.

The original practice was as follows:

If the actual height is not greater than pixel PX, there is no problem. If the actual height of one side is greater than pixel PX, the height of the other side can only be defined as pixel PX, does not meet the actual needs.

After testing, js can solve this problem.

The Code is as follows:

Var h = document. getElementById ("left"). offsetHeight> document. getElementById ("right"). offsetHeight? Document. getElementById ("left"). offsetHeight: document. getElementById ("right"). offsetHeight;
Document. getElementById ("ztleft"). style. height = document. getElementById ("ztright"). style. height = h + "px ";

If it is a dynamically generated p, as long as you try to get the id and store it in the js array, the problem can also be simply solved using loops.

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.