CSS制作超棒搜索框

84 篇文章 0 订阅

CSS制作超棒搜索框

教程地址原文地址(YouTube)

两个视频的内容相同,第二个为转载

效果图

在这里插入图片描述

代码区

以下代码为本人填写,转载请注明教程地址和本贴地址

html

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<link type="text/css" href="style.css" rel="stylesheet" />
		<script src="https://use.fontawesome.com/1ff3fda05c.js"></script>
		<title></title>
	</head>
	<body>
		<div class="search-box">
			<input class="search-txt" type="text" name="" placeholder="搜索信息" />
			<a class="serach-btn" href="#">
				<i class="fa fa-search" aria-hidden="true"></i>
			</a>
		</div>
	</body>
</html>

CSS

body{
	margin: 0; /*外边距*/
	padding: 0; /*内边距*/
	background: #e84118; /*背景颜色*/
}
.search-box{
	position:absolute; /*绝对定位*/
	top: 50%; /*距上部*/
	left: 50%; /*距左部*/
	transform: translate(-50%,-50%); /*修改动画定位*/
	background: #2f3640;
	height: 40px;
	border-radius: 40px; /*边框圆角*/
	padding: 10px;
}
.search-box:hover > .search-txt{ /*子元素*/
	width: 240px;
	padding:  0 6px;
}
.search-box:hover > .serach-btn{
	background: white;
	transform: rotateY(360deg); /*Y轴旋转*/
	}
.serach-btn{
	color: #e84118;
	float: right;
	width: 40px;
	height: 40px;
	border-radius: 50%;
	background: #2f3640;
	display: flex; /*盒模型*/
	justify-content: center; /*主轴对齐方式*/
	align-items: center; /*副轴对齐方式*/
	transition: 1.8s;	 /*过渡时间*/
}
.search-txt{
	border: none; /*边框无*/
	background: none;
	outline: none; /*轮廓*/
	float: left;
	padding: 0;
	color: white;
	font-size: 16px;
	transition: 0.5s;
	line-height: 40px; /*行高*/
	width: 0px;
}

JS


教程地址原文地址(YouTube)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值