css-50 Projects in 50 Days(4)

html

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>输入框隐藏</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css"
        integrity="sha512-1PKOgIY59xJ8Co8+NE6FZ+LOAZKjy+KY8iq0G4B3CyeY6wYHN3yt9PW0XpSriVlkMXe40PTKnXrLnZ9+fkDaog=="
        crossorigin="anonymous">
    <link rel="stylesheet" href="./index.css">
</head>

<body>
    <div class="search_wrapper">
        <input id="search_input" type="text" placeholder="请输入搜索内容" class="search_input "></input>
        <button id="search_btn" class="search_btn ">
            <i class="fas fa-search"></i>
        </button>
    </div>
    <script src="./index.js"></script>
</body>

</html>

css

css 复制代码
body {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: pink;
    height: 100vh;
}

.search_wrapper {
    display: flex;
    align-items: center;
    position: relative;

    .search_input {
        width: 50px;
        height: 50px;
        border: 0;
        padding: 0 16px;
        box-sizing: border-box;
        transition: .3s all ease;
        outline: 0;
    }

    .search_btn {
        width: 50px;
        height: 50px;
        position: absolute;
        left: 0;
        top: 0;
        border: 0;
        font-size: 24px;
        cursor: pointer;
        background-color: #fff;
        transition: .3s all ease;
    }

    .search_input_active {
        width: 200px;

    }

    .search_btn_active {
        transform: translateX(198px);
    }
}

js

javascript 复制代码
const state = {
    searchInputEl: document.querySelector('.search_input'),
    searchBtnEl: document.querySelector('.search_btn')
}

state.searchBtnEl.onclick = function () {
    state.searchInputEl.classList.toggle('search_input_active')
    state.searchInputEl.focus()
    state.searchBtnEl.classList.toggle('search_btn_active')
}
相关推荐
子兮曰5 小时前
async/await高级模式:async迭代器、错误边界与并发控制
前端·javascript·github
恋猫de小郭5 小时前
2026 Flutter VS React Native ,同时在 AI 时代 VS Native 开发,你没见过的版本
android·前端·flutter
GIS之路7 小时前
ArcGIS Pro 中的 Notebooks 入门
前端
IT_陈寒9 小时前
React状态管理终极对决:Redux vs Context API谁更胜一筹?
前端·人工智能·后端
Kagol10 小时前
TinyVue 支持 Skills 啦!现在你可以让 AI 使用 TinyVue 组件搭建项目
前端·agent·ai编程
柳杉10 小时前
从零打造 AI 全球趋势监测大屏
前端·javascript·aigc
simple_lau10 小时前
Cursor配置MasterGo MCP:一键读取设计稿生成高还原度前端代码
前端·javascript·vue.js
睡不着先生10 小时前
如何设计一个真正可扩展的表单生成器?
前端·javascript·vue.js
天蓝色的鱼鱼10 小时前
模块化与组件化:90%的前端开发者都没搞懂的本质区别
前端·架构·代码规范
明君8799710 小时前
Flutter 如何给图片添加多行文字水印
前端·flutter