登录  /  注册
首页 > web前端 > css教程 > 正文

使用css实现自适应标题浮动效果(代码实例)

青灯夜游
发布: 2021-04-15 12:33:33
转载
1477人浏览过

本篇文章通过代码实例给大家介绍一下css实现自适应标题浮动效果的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

(学习视频分享:css视频教程

效果展示:

1.gif

源码展示:

<!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>
登录后复制

更多编程相关知识,请访问:编程视频!!

以上就是使用css实现自适应标题浮动效果(代码实例)的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
相关标签:
css
来源:csdn网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号