Make the Editable Div adaptive size

Source: Internet
Author: User

The editable div is <Div contenteditable = 'true'> </div>. I don't know who has ever encountered this problem. I encountered this problem when I was doing HTML editor last time, you can set a div to a specific size such as width = 300px and Height = 100px. However, when the width and height attributes of a div are set to width = 100%, when Height = 100%, the DIV size is reduced to the text size. If you set the DIV overflow style to scroll, The DIV size remains unchanged during editing, it's really annoying.
 
Fortunately, after a long time, I finally solved this problem. The key to setting width and height to 100% is to refer to the size of its parent container, that is to say, the width and height values must be set for other HTML tags containing the div, if both values are set to 100%, you should ensure that the width and height attributes of the HTML Tag are also set, and so on.

If the DIV is in the outermost layer and you want to fill the entire window with the DIV, you must set the width and height attributes of the body and HTML Tag, as shown below:

Body {} {Widht:100%;Height:100%;}
Html {} {Width:100%;Height:100%;}

Set the width and height attributes of the DIV to 100% to fill the entire window.

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.