用一个div模拟textarea的实现【前端每日一题-15】

用一个div模拟textarea的实现?

考点:html

  • contenteditable属性

答案:bash

<!DOCTYPE html>
<head>
    <title>div模拟textarea</title>
    <style>
        .editdiv{
            border:1px solid #a0b3d6;
            width: 500px;
            min-height: 200px;
            font-size: 14px;
            padding: 4px;
            color: #333;
            outline:0; /* 解决聚焦边框 */
        }

        /* 添加placeholder属性 */
        .editdiv:empty::before{
            content:attr(placeholder);
            color: #999;
        }
    </style>
</head>
<body>
    <div class="editdiv" contenteditable="true" placeholder="请输入内容..."></div>
</body>
</html>复制代码
相关文章
相关标签/搜索