简体   繁体   中英

Make DIV stylized as textarea and containing formatted text editable

I have this div:

<div class="textarea"></div>

which I stylized as textarea with this css:

.textarea {
    -moz-appearance: textfield-multiline;
    -webkit-appearance: textarea;
    border: 1px solid gray;
    font: medium -moz-fixed;
    font: -webkit-small-control;
    height: 28px;
    overflow: auto;
    padding: 2px;
    resize: both;
    width: 100%;
}

Now, If I add some html code inside this div, even the cursor is not shown there. Can I make this div editable?

Just change the contentEditable attribute to true, and you're sorted

 .textarea { -moz-appearance: textfield-multiline; -webkit-appearance: textarea; border: 1px solid gray; font: medium -moz-fixed; font: -webkit-small-control; height: 28px; overflow: auto; padding: 2px; resize: both; width: 100%; }
 <div class="textarea" contentEditable="true"></div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM