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')
}
相关推荐
前端_yu小白11 分钟前
react常用优化手段
前端·javascript·react.js·性能优化·usecallback·usememo
攀登的牵牛花13 分钟前
前端向架构突围系列 - 框架设计(六):解析接口职责的单一与隔离
前端·架构
开开心心_Every18 分钟前
离线黑白照片上色工具:操作简单效果逼真
java·服务器·前端·学习·edge·c#·powerpoint
Mintopia25 分钟前
🌌 信任是否会成为未来的货币?
前端·人工智能·aigc
fqbqrr26 分钟前
2601C++,模块导出分类
前端·c++
倚栏听风雨31 分钟前
vscode 运用 ts 代码需要准备什么
前端
韩曙亮39 分钟前
【Web APIs】浏览器本地存储 ① ( window.sessionStorage 本地存储 | window.localStorage 本地存储 )
服务器·前端·javascript·本地存储·localstorage·sessionstorage·web apis
吃杠碰小鸡42 分钟前
前端Mac快速搭建开发环境
前端·macos
前端大波1 小时前
使用webpack-bundle-analyzer 对 react 老项目进行打包优化
前端·react.js·webpack·性能优化
前端 贾公子1 小时前
(catalog协议) == pnpm (5)
前端·javascript·react.js