多行textarea输入内容,进行水平垂直居中

多行textarea输入内容,进行水平垂直居中

代码如下:

<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>textarea多行内容的水平垂直居中</title>
</head>

<style>
    .divBox {
        width: 200px;
        height: 200px;
        margin-top: 20px;
        margin-left: 50px;
        display: flex;
        justify-content: center;
        align-items: center;
        border: 1px solid #dedede;
    }

    .textareaBox {
        border: none;
        text-align: center;
        width: 200px;
        max-height: 200px;
        overflow: auto;
        word-break: break-all;
        resize: none;
    }

    .textareaBox:focus {
        outline: none;
    }
</style>

<body>
    <div class="divBox">
        <textarea class="textareaBox"></textarea>
    </div>
    <script src="https://cdn.staticfile.org/jquery/1.10.0/jquery.min.js"></script>
    <script>
        $(".textareaBox").on('input', function () {
            this.style.height = 'auto';
            this.style.height = this.scrollHeight + "px";
        });
    </script>
</body>

</html>

效果如图:
在这里插入图片描述
原文请见:https://www.cnblogs.com/keenjade/p/11463138.htmlhtm

如有漏洞,欢迎互动指教!!!!!!!!!!!!!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值