2021-07-30——隐藏搜索

css代码,样式的设置

<style>
			*{
				margin: 0;
				padding: 0;
				box-sizing: border-box;
			}
			body{
				background-image:inherit;
				font-family: "微软雅黑";
				display: flex;
				justify-content: center;
				align-items: center;
				height: 100vh;
			}
			.search{
				height: 50px;
				position: relative;
				
			}
			.search input{
				
				background-color: cornflowerblue;
				border: 0;
				font-size: 18px;
				height: 50px;
				width: 50px;
				transition: width 0.3s ease;
			}
			.btn{
				background-color: palegreen;
				border: 0;
				color: red;
				cursor: pointer;
				padding: 15px;
				height: 50px;
				width: 50px;
				transition: transform 0.3 ease;	
				position: absolute;
				left: 0;
				top: 0;
				font-size: 24px;		
			}
			.btn :focus,input:focus{
				outline: 0;
			}
			.search.active input{
				width: 200px;
			}
			.search.active button{
				transform: translateX(200px);
			}
		</style>```



**

全代码可以直接使用

**

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>搜索</title>
		<style>
			*{
				margin: 0;
				padding: 0;
				box-sizing: border-box;
			}
			body{
				background-image:inherit;
				font-family: "微软雅黑";
				display: flex;
				justify-content: center;
				align-items: center;
				height: 100vh;
			}
			.search{
				height: 50px;
				position: relative;
				
			}
			.search input{
				
				background-color: cornflowerblue;
				border: 0;
				font-size: 18px;
				height: 50px;
				width: 50px;
				transition: width 0.3s ease;
			}
			.btn{
				background-color: palegreen;
				border: 0;
				color: red;
				cursor: pointer;
				padding: 15px;
				height: 50px;
				width: 50px;
				transition: transform 0.3 ease;	
				position: absolute;
				left: 0;
				top: 0;
				font-size: 24px;		
			}
			.btn :focus,input:focus{
				outline: 0;
			}
			.search.active input{
				width: 200px;
			}
			.search.active button{
				transform: translateX(200px);
			}
		</style>
	</head>
	<body>
		<div class="search">
			<input type="text" class="input" placeholder="搜索" />
			<button class="btn">
				<i class="fas fa"></i>
			</button>
		</div>
		<script>
			const search=document.querySelector('.search');
			const btn=document.querySelector('.btn');
			const input =document.querySelector('.input');
			btn.addEventListener('click',()=>{
				search.classList.toggle('active');
				input .focus();
			})
		</script>
	</body>
	
</html>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值