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')
}
相关推荐
浪裡遊27 分钟前
Nivo图表库全面指南:配置与用法详解
前端·javascript·react.js·node.js·php
漂流瓶jz2 小时前
快速定位源码问题:SourceMap的生成/使用/文件格式与历史
前端·javascript·前端工程化
samroom2 小时前
iframe实战:跨域通信与安全隔离
前端·安全
fury_1232 小时前
vue3:数组的.includes方法怎么使用
前端·javascript·vue.js
weixin_405023372 小时前
包资源管理器NPM 使用
前端·npm·node.js
宁&沉沦2 小时前
Cursor 科技感的登录页面提示词
前端·javascript·vue.js
Dragonir2 小时前
React+Three.js 实现 Apple 2025 热成像 logo
前端·javascript·html·three.js·页面特效
peachSoda73 小时前
封装一个不同跳转方式的通用方法(跳转外部链接,跳转其他小程序,跳转半屏小程序)
前端·javascript·微信小程序·小程序
@PHARAOH4 小时前
HOW - 浏览器兼容(含 Safari)
前端·safari