html输入框placeholder颜色_表单输入框聚焦效果

虽互不曾谋面,但希望能和您成为笔尖下的朋友

以读书,技术,生活为主,偶尔撒点鸡汤

不作,不敷衍,意在真诚吐露,用心分享

点击左上方,可关注本刊

标星公众号(ID:itclanCoder)

如果不知道如何操作

点击这里,标星不迷路

━━━━━━

7bb1993e112d445927fd5c46f738c257.png

前言

让表单的输入框动起来

单个输入框表单聚焦时输入框变化

82a79d1f6b2490494f02130bc0b4483d.gif

html 结构代码

type="text" placeholder="请输入您的姓名" />

css 代码,当然你使用类选择器也是可以的,这里我使用了 css 的属性选择器 关于选择器的优先级,可自行尝试测试:

内联样式 > ID 选择器 > 类选择器 = 属性选择器 = 伪类选择器 > 标签选择器 = 伪元素选择器

css代码

input[type='text'] {
  height: 40px;
  width: 200px;
  background: transparent; // 背景透明
  border: none;
  border-bottom: 1px solid #999;
  text-indent: 20px;
  transition: 0.3;
  outline: none;
}
input[type='text']:hover {
  // 鼠标经过输入框时,更改border颜色
  border-color: #42b983;
}

input[type='text']:focus {
  // 鼠标聚焦焦点时
  border-bottom-color: #f1190d;
}

input[type='text']::-webkit-input-placeholder {
  // 实现该效果主要在这里
  transition: 0.5s; // 过度0.5s
  font-size: 14px; // 字体变为14px
  transform-origin: top left; // 属性允许您改变被转换元素的位置,从上到左,x轴水平方向top,y轴垂直方向left
}

input[type='text']:focus::-webkit-input-placeholder {
  transform: scale(0.8) translateY(-10px); // 缩小0.8倍,同时向上垂直方向平移10px
}

多个输入框表单聚焦时输入框变化

2b500864b76b3ab85932e2bb8161ddab.gif

input[type='text'],
input[type='password'] {
  height: 40px;
  width: 200px;
  background: transparent;
  border: none;
  border-bottom: 1px solid #999;
  text-indent: 20px;
  transition: 0.3;
  outline: none;
}
input[type='text']:hover,
input[type='password']:hover {
  border-color: #42b983;
}

input[type='text']:focus,
input[type='password']:focus {
  border-bottom-color: #f1190d;
}

input[type='password']::-webkit-input-placeholder,
input[type='text']::-webkit-input-placeholder {
  transition: 0.5s;
  font-size: 14px;
  transform-origin: top left;
}
input[type='password']:focus::-webkit-input-placeholder,
input[type='text']:focus::-webkit-input-placeholder {
  transform: scale(0.8) translateY(-10px);
}

分析

实现这一效果,主要在于-webkit-input-placeholder这个伪元素的方式,结合 css 中的变换transform,缩小scale,与垂直方向平移

85f4d1f5a2068219de5730a11010baa3.png

公众号(ID:itclanCoder)

码能让您早脱菜籍,文能让您洗净铅华

  可能您还想看更多:

efc9075012dd6ab96901e946800b0d57.png

理解 Es6 中的 Symbol 类型

06e9c4d82618e37c986ecd58a9ac6446.png

微信小程序中 setData 详解

dcc31be038bb149142e44f0be6f97a92.png

小程序-云开发-多图片内容安全检测

原文出处: https://coder.itclan.cn/fontend/css/example-input-focus-animate/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值