Textarea text area width and height width and height automatic adaptation implementation code

Textarea text area width and height width and height automatic adaptation implementation code

Copy code
The code is as follows:

<HTML>
<HEAD>
<TITLE>Textarea width and height automatic adaptation processing method</TITLE>
<!-- Automatic adaptation of control width-->
<style type="text/css">
.comments {
width:100%;/*Automatically adapt to the width of the parent layout*/
overflow:auto;
word-break:break-all;
/*Solve the line break problem in IE (prevent it from being automatically displayed in one line, mainly to solve the IE compatibility problem. In IE8, when the width is set to 100%, if the text field capacity exceeds one line,
When we double-click the text content, it will automatically change to a single line, so we can only use IE's proprietary line break properties "word-break or word-wrap" to control its line break)*/
}
</style>
</HEAD>

<BODY>
<FORM METHOD=POST ACTION= " ">
<!-- Mainly controls the automatic adaptation of height -->

<!-- The first one is a normal textarea -->
<textarea class="comments" rows="10" cols="10"> </textarea>
<!-- The following two methods can solve the problem of textarea line height automatically adapting to the height of the class content-->
<textarea class="comments" rows=1 name=s1 cols=27 onpropertychange= "this.style.posHeight=this.scrollHeight "></textarea>

<textarea class="comments" style="height:expression((this.scrollHeight>150)?'150px':(this.scrollHeight+5)+'px');overflow:auto;"></textarea>
</FORM>
</BODY>
</HTML>

<<:  Three Discussions on Iframe Adaptive Height Code

>>:  jQuery solves the problem of not executing the original event after adding elements

Recommend

Before making a web page, let’s take a look at these so-called specifications

This article has compiled some so-called specific...

Linux beginners in virtual machines configure IP and restart the network

For those who are new to virtual machines or have...

MySQL DML language operation example

Additional explanation, foreign keys: Do not use ...

Bugs encountered when using mybatis-generator with mysql8.0.3 in IDEA

1. Add the plug-in and add the following configur...

Example of automatic import method of vue3.0 common components

1. Prerequisites We use the require.context metho...

What are the benefits of using B+ tree as index structure in MySQL?

Preface In MySQL, both Innodb and MyIsam use B+ t...

How to modify the firewall on a Linux server to allow remote access to the port

1. Problem Description For security reasons, the ...

HTML Code Writing Guide

Common Convention Tags Self-closing tags, no need...

Details of using Vue slot

Table of contents 1. Why use slots? 1.1 slot 1.2 ...

Web Design Experience: Efficiently Writing Web Code

Originally, this seventh chapter should be a deep ...

Element sample code to implement dynamic table

Table of contents 【Code background】 【Code Impleme...

MySQL enables slow query (introduction to using EXPLAIN SQL statement)

Today, database operations are increasingly becom...

A brief discussion on the perfect adaptation solution for Vue mobile terminal

Preface: Based on a recent medical mobile project...