使用css实现自适应标题浮动效果(代码实例)
4741
本篇文章通过代码实例给大家介绍一下css实现自适应标题浮动效果的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
效果展示:
源码展示:
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>纯css实现自适应标题浮动效果</title>
- <style>
- body {
- background-color:#FAFAFA;
- }
- input[type="text"] {
- -webkit-box-sizing:border-box;
- -moz-box-sizing:border-box;
- box-sizing:border-box;
- width:100%;
- height:-webkit-calc(3em + 2px);
- height:calc(3em + 2px);
- margin:0 0 1em;
- padding:1em;
- border:1px solid #cccccc;
- border-radius:1.5em;
- background:#fff;
- resize:none;
- outline:none;
- }
- input[type="text"][required]:focus {
- border-color:#00bafa;
- }
- input[type="text"][required]:focus + label[placeholder]:before {
- color:#00bafa;
- }
- 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(0,-1.5em) scale(0.9,0.9);
- -ms-transform:translate(0,-1.5em) scale(0.9,0.9);
- transform:translate(0,-1.5em) scale(0.9,0.9);
- }
- 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:2.3em;
- margin-top:-webkit-calc(-3em - 2px);
- margin-top:calc(-3em - 2px);
- margin-bottom:-webkit-calc((3em - 1em) + 2px);
- margin-bottom:calc((3em - 1em) + 2px);
- }
- input[type="text"][required] + label[placeholder]:before {
- content:attr(placeholder);
- display:inline-block;
- margin:0 -webkit-calc(1em + 2px);
- margin:0 calc(1em + 2px);
- padding:0 2px;
- color:#898989;
- white-space:nowrap;
- -webkit-transition:0.3s ease-in-out;
- transition:0.3s ease-in-out;
- background-image:-webkit-gradient(linear,left top,left bottom,from(#ffffff),to(#ffffff));
- background-image:-webkit-linear-gradient(top,#ffffff,#ffffff);
- background-image:linear-gradient(to bottom,#ffffff,#ffffff);
- -webkit-background-size:100% 5px;
- background-size:100% 5px;
- background-repeat:no-repeat;
- background-position:center;
- }
- </style>
- </head>
- <body>
- <div style="width:400px;height:100px;margin:50px auto">
- <form>
- <input required="" type="text">
- <label alt="请输入用户名" placeholder="名称"></label>
- </form>
- </div>
- </body>
- </html>
本文网址:https://www.zztuku.com/index.php/detail-8797.html
站长图库 - 使用css实现自适应标题浮动效果(代码实例)
申明:如有侵犯,请 联系我们 删除。
您还没有登录,请 登录 后发表评论!
提示:请勿发布广告垃圾评论,否则封号处理!!