js+css实现图标伸缩式搜索框代码

代码语言:html

所属分类:搜索

代码描述:js+css实现图标伸缩式搜索框代码

代码标签: js css 图标 伸缩式 搜索框 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/ionicons.esm.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/ionicons.7.1.0.js"></script>
<style>
    * {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
}

.container {
	width: 100vw;
	height: 100vh;
	display: flex;
	justify-content: center;
	align-items: center;
	background-color: #a1afc9;
}

.search-bar {
	width: 60px;
	height: 60px;
	background-color: #fff;
	box-shadow: 0 0 10px #999;
	/* 搜索栏会撑开,因此使用具体数值 */
	border-radius: 60px;
	display: flex;
	align-items: center;
	position: relative;
	overflow: hidden;
	transition: all 0.3s ease-in;
}

.change-width {
	width: 500px;
	z-index: 1;
}

.search-icon {
	width: 60px;
	height: 60px;
	background-color: #4b5cc4;
	/* 搜索栏会撑开,因此使用具体数值 */
	border-radius: 60px;
	display: flex;
	justify-content: center;
	align-items: center;
	cursor: pointer;
	/* 需要加高层级,遮盖缩小时其他按钮 */
	z-index: 1;
}

.search-icon ion-icon {
	font-size: 25px;
	color: #fff;
	font-weight: 900;
}

.search-input {
	/* 使用父元素宽度减去一定宽度,不遮挡右边圆角样式即可 */
	width: calc(100% - 90px);
	height: 60px;
	background-color: #4b5cc4;
}

.search-input input {
	width: 100%;
	height: 100%;
	/* 去掉默认边框 */
	border: none;
	/* 去掉输入时默认边框 */
	outline: none;
	font-size: 18px;
	padding-left: 10px;
}

.search-input .clear {
	width: 20px;
	height: 20px;
	cursor: pointer;
	display: flex;
	justify-content: center;
	align-items: center;
	position: absolute;
	right: 18%;
	top: 50%;
	transform: translateY(-50%);
	border-rad.........完整代码请登录后点击上方下载按钮下载查看

网友评论0