css3 用户自己控制div元素的尺寸,类似于textarea文本框

效果图:

 css代码:添加这个两行代码就可以实现

 div{
   resize:both;
	overflow:auto;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 textarea 的右下角显示输入的总字数,可以通过 CSS 实现。 首先,给 textarea 添加一个 class,比如 `text-area`。然后,使用 CSS 选择器来选中该 class,并使用 `position: relative` 属性使其成为相对定位的元素。 接下来,创建一个 `<span>` 元素用于显示总字数,并给它一个 class,比如 `word-count`。在该 class 的样式中,使用 `position: absolute` 和 `bottom: 5px` 以及 `right: 5px` 来将其定位在 textarea 的右下角。 最后,在 Vue 组件中,将计算属性 `totalWordsCount` 绑定到 `<span>` 元素上,使用插值语法 `{{ }}` 将计算出的总字数显示在页面上。 以下是一个示例代码: ```vue <template> <div> <textarea class="text-area" v-model="inputText"></textarea> <span class="word-count">{{ totalWordsCount }}/200</span> </div> </template> <style> .text-area { position: relative; } .word-count { position: absolute; bottom: 5px; right: 5px; } </style> <script> export default { data() { return { inputText: '', totalWords: 0 }; }, computed: { totalWordsCount() { let count = this.inputText.length; if (count > 200) { this.inputText = this.inputText.slice(0, 200); count = 200; } return count; } } }; </script> ``` 在上述示例中,通过在 textarea 上添加 `text-area` 类,并在 `<span>` 元素上添加 `word-count` 类,来设置它们的样式。通过 `position: relative` 和 `position: absolute` 属性,以及 `bottom` 和 `right` 属性来实现定位。然后,通过插值语法将计算属性 `totalWordsCount` 绑定到 `<span>` 元素上,将总字数显示在页面的右下角。 请注意,上述示例还添加了字数限制的逻辑,如果输入文本超过 200 字,会将其截断为前 200 字,并将总字数设置为 200。你可以根据需要调整这部分逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值