CSS自适应的占位符效果
一种不错的自适应input效果,分享一下。 html section :
<div style="width:500px;height:500px;margin:300px auto;border: 1px solid red;">
<form style="width: 280px; height: 500px; margin:1em auto;">
<input required='' type='text'/>
<label alt='请输入旧密码' placeholder='请输入旧密码'></label>
<input required='' type='text'/>
<label alt='请输入新密码' placeholder='请输入新密码'></label>
<input required='' type='text'/>
<label alt='请确认新密码' placeholder='请确认新密码'></label>
</form>
</div>
style section :
input[type="text"] {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
width: 100%;
margin: 0 0 10px;
padding: 12px;
border: 1px solid #cccccc;
border-radius: 5px;
background: #fff;
resize: none;
outline: none;
}
input[type="text"][required]:focus {
box-shadow: 1px 1px 5px #444;
-webkit-transition-duration: .2s;
transition-duration: .2s;
pointer-events: none;
}
input[type="text"][required]:focus + label[placeholder]:before {
color: #000;
}
input[type="text"][required]:focus + label[placeholder]:before,
input[type="text"][required]:valid + label[placeholder]:before {
-webkit-transition-duration: .2s;
transition-duration: .2s;
-webkit-transform: translate(-110px,10px) scale(0.9, 0.9);
/*-ms-transform: translate(-110px,10px) scale(0.8, 0.8);*/
transform: translate(-110px,10px) scale(0.9, 0.9);
color: #00FFFF;
/*字体缩放*/
}
input[type="text"][required]:invalid + label[placeholder][alt]:before {
content: attr(alt);
}
input[type="text"][required] + label[placeholder] {
display: block;
pointer-events: none;
line-height: 36px;
/*placeholder position*/
margin-top: -webkit-calc(-48px - 2px);
margin-top: calc(-48px - 2px);
margin-bottom: -webkit-calc((40px - 10px) + 2px);
margin-bottom: calc((40px - 10px) + 2px);
}
input[type="text"][required] + label[placeholder]:before {
content: attr(placeholder);
display: inline-block;
margin: 0 -webkit-calc(1em + 2px);
margin: 0 calc(10px + 2px);
padding: 0 2px;
color: #898989;
white-space: nowrap;
-webkit-transition: 0.3s ease-in-out;
transition: 0.3s ease-in-out;
-webkit-background-size: 100% 5px;
background-size: 100% 5px;
background-repeat: no-repeat;
background-position: center;
}
效果图 :
但是IE不兼容,具体效果可以自己测试一下,当鼠标点击input时占位符是淡出去的效果。
CSS自适应的占位符效果的更多相关文章
- Adaptive Placeholder – 自适应的占位符效果
在早期,我们都是通过使用 JavaScript 来实现占位符功能.而现在,HTML5 原生提供的 placeholder 属性让我们在现代浏览器轻松就能实现这样的功能.这里向大家分享一个自适应的占位符 ...
- css实现简单音乐符效果
css实现简单音乐符效果 利用css3中的transform.animation.keyframes实现 <!DOCTYPE html> <html lang="en&qu ...
- css编译工具Sass中混合宏,继承,占位符分别在什么时候使用
//SCSS中混合宏使用 @mixin mt($var){ margin-top: $var; } .block { @include mt(5px); span { display:block; @ ...
- [Sass]占位符 %placeholder
[Sass]占位符 %placeholder Sass 中的占位符 %placeholder 功能是一个很强大,很实用的一个功能,这也是我非常喜欢的功能.他可以取代以前 CSS 中的基类造成的代码冗余 ...
- Sass占位符选择器`%`
摘录自Understanding placeholder selectors. @extend @extend让你能够在多个选择器中通过继承的方式共享一段样式: .icon { transition: ...
- sass中 混合宏 VS 继承 VS 占位符 各自的使用时机和特点
初学者都常常纠结于这个问题“什么时候用混合宏,什么时候用继承,什么时候使用占位符?”其实他们各有各的优点与缺点,先来看看他们使用效果: a) Sass 中的混合宏使用 举例代码见 2-24 行 编译出 ...
- sass中的占位符%,@extend,@mixin(@include)的编译区别和使用场景
对于下面同一段css,它们的编译效率是不同的. 1.使用@extend:基础类icon会出现在编译后的css文件中,即使它可能只是拿来被继承,而不是作为icon这个class单独使用 //基础类ico ...
- Sass--混合宏 VS 继承 VS 占位符
什么时候用混合宏,什么时候用继承,什么时候使用占位符?”其实他们各有各的优点与缺点,先来看看他们使用效果: a) Sass 中的混合宏使用 总结:编译出来的 CSS 清晰告诉了大家,他不会自动合并相同 ...
- .NET 基础 一步步 一幕幕[运算符、占位符、转义符]
运算符.占位符.转义符 好吧,在五局全胜之后,终于升到了三个钻,距离一个星星还有一大段距离,忽然想起来今天的博客还没写,果断坑队友,来写博客了....感觉以后还是每天更新一篇比较好.要不晚上就该熬 ...
随机推荐
- 【方法】Html5实现文件异步上传
1 简介 开发文件上传功能从来不是一件愉快的事,异步上传更是如此,使用过iframe和Flash的上传方案,也都感觉十分的别扭.本文简要简绍利用Html5的FormData实现文件的异步上传,还可以实 ...
- 详谈JAVA中的file类与IO流
File类 位置于java.io包构造方法:File(String parent, String child)new file("d:\\","a.txt") ...
- Cannot be cast to java.lang.Comparable异常
Set集合中的treeSet问题:cannot be cast to java.lang.Comparable: 原理: Set不保存重复的元素,与Collection类似,只是行为不同,Set是基于 ...
- R笔记(1):formula和Formula
#####开一个新的系列.关于R的一些笔记,就是遇到过的一些问题的简单整理.可能很基本,也可能没什么大的用处,作为一个记录而已.------------------------------------ ...
- spring和hibernate的整合
阅读目录 一.概述 二.整合步骤 1.大致步骤 2.具体分析 一.概述 Spring整合Hibernate有什么好处? 1.由IOC容器来管理Hibernate的SessionFactory 2.让H ...
- Scrapy的debug方式
Scrapy不方便调试,但是为了深入学习框架内部的一些原理,有时候仅仅依靠日志是不够的.下面提供一种scrapy的debug方式 demo直接用来自官方例子来演示:https://github.com ...
- 安迪的第一个字典(Andy's First Dictionary,UVa 10815)
Description Andy, , has a dream - he wants to produce his very own dictionary. This is not an easy t ...
- {新人笔记 勿看} spring mvc第一步
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- javaCV开发详解之5:录制音频(录制麦克风)到本地文件/流媒体服务器(基于javax.sound、javaCV-FFMPEG)
javaCV系列文章: javacv开发详解之1:调用本机摄像头视频 javaCV开发详解之2:推流器实现,推本地摄像头视频到流媒体服务器以及摄像头录制视频功能实现(基于javaCV-FFMPEG.j ...
- OWIN的概念初接触
OWIN这个词我昨天才认识,一直疑惑它是个什么东西,通过一定量的研究,得到一个初步的认识,留个脚印. OWIN是什么 OWIN是一个规范和标准,旨在阐述web服务器和web应用应该如何去解耦,它使得原 ...