1、文本框默认点击特效:

用css或js实现文本输入框的特效

点击文本框,外围会出现蓝色阴影,取消该特效,为该文本框添加css样式"outline:none; box-shadow:none",就取消了默认特效。必要时可以加!important增加优先级

2、实现百度搜索框点击特效:

用css或js实现文本输入框的特效

点击文本框,文本框的边框出现蓝色实线,我学习到的实现方法:

基础的html元素:

用css或js实现文本输入框的特效

 

css:为需要该特效的文本框设置该css样式

用css或js实现文本输入框的特效

js:当鼠标点击该文本框时,该文本框的类名改变

用css或js实现文本输入框的特效

 3、输入框特殊点击特效

用css或js实现文本输入框的特效

 

 实现代码:

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>test2</title>
</head>

<body>
    <div class="main">
        <form style="margin-top:50px;">
            <input type="text">
            <span class="span">
                <label>用户名 :</label>
            </span>
        </form>
    </div>
    <style>
        .main {
            height: 500px;
            width: 800px;
            margin: auto;
        }
        
        .main form {
            position: relative;
            font-weight: blod;
        }
        
        .main input {
            height: 50px;
            width: 300px;
            margin: auto;
            border: 0;
            box-shadow: none;
            border-bottom: 1px solid #6a7989;
            transition: border-bottom 0.5s;
        }
        
        .main .span {
            position: absolute;
            left: 0;
            bottom: 0;
            height: 50px;
        }
        
        .main label {
            font-weight: bold;
            color: #6a7989;
            line-height: 50px;
            display: block;
        }
        
        .main input:focus {
            outline: none;
            border-bottom: 2px solid aqua;
        }
    </style>
    <script>
        window.onload = function() {
            var span = document.getElementsByTagName('span');
            var input = document.getElementsByTagName('input');
            input[0].onfocus = function() {
                span[0].style.bottom = '30px';
            }
            input[0].onblur = function() {
                span[0].style.bottom = '0';
            }
        }
    </script>
</body>

</html>
View Code

相关文章:

  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2021-11-29
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2022-01-25
  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案