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')
}
相关推荐
anOnion6 小时前
构建无障碍组件之Menu Button pattern
前端·html·交互设计
用户47949283569156 小时前
claude Fable用不了?把Gpt 5.5pro接到你的claude code里
前端·后端
zhangxingchao9 小时前
Kotlin常用的Flow 操作符整理
前端
IT_陈寒10 小时前
React的useState居然还有这种坑?我差点删库跑路
前端·人工智能·后端
Pedantic11 小时前
SwiftUI 手势笔记
前端·后端
橙子家12 小时前
浏览器缓存之【结构化数据库与缓存】: IndexedDB、Cache storage 和 Storage buckets
前端
user205855615181312 小时前
X6 中边悬浮置顶,规避 `mouseleave` 事件丢失问题
前端
李明卫杭州12 小时前
CSS aspect-ratio 属性完全指南
前端
Pedantic14 小时前
SwiftUI 手势层级(Gesture Hierarchy)详解
前端