html、css做一个带搜索图标的搜索框

html、css图像代替提交按钮 做个搜索框

图像形式的提交按钮与普通提交按钮在功能上基本相同,只是它用图像代替了默认的提交按钮,外形上更加美观。需要注意的是,必须为其定义src属性指定图像的url地址!

最终效果图如下:

在这里插入图片描述

😊😊😊 具体代码如下
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>将提交按钮做成图片</title>
	<style>
    	.box{
    		width:220px;
    		height: 57.5px;
    		background-color: #FFF5EE;
    		position: relative;
    		margin:50px auto auto 50px;
    		border:solid silver 0.5px;
    		border-radius: 10px 10px 10px 10px ;

    	}
    	#text{
    		width:170px;
    		height: 52.5px;
    		font-size: 19px;
    		border-radius: 10px 10px 10px 10px ;
    		background-color: #FFF5EE;
    		border:solid silver 0.5px;
    		position: absolute;
    		left:0px;
    		top:0px; 

    	}
    	#search{
    		width: 58px;
    		height:58px;
    		font-size: 19px;
    		border-radius: 10px 10px 10px 10px ;
    		position: absolute;
    		right: 0px;
    		top: 0px;
    	}
    </style>
</head>

<body>
	<!-- 将按提交按钮 和文本框放在一个同盒子里 通过定位是调整它们的位置 -->
	<div class ="box">
		<input type="text" placeholder="请输入搜索内容" id="text">
		<input type="image" src="images/sou.png" id="search">
	</div>
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="知识共享许可协议" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />本作品采用<a rel="license" href="http://creativecommons.org/licenses/by/4.0/">知识共享署名 
</body>
</html>
小sunny在设计学校网页时 遇到了一个搜索框于是就想出了上面的方法,时间仓促上面的效果图做的有点简陋😁,哈哈ヾ(≧▽≦*)o,当然你们可以按照自己的风格设计出自己喜欢的样式啦!
ヾ(≧▽≦*)o😊喜欢的话就留个赞吧!
  • 7
    点赞
  • 54
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用以下 HTMLCSS 代码来创建一个搜索图标搜索框HTML 代码: ```html <div class="search-box"> <form action="/search" method="get"> <input type="text" placeholder="Search..."> <button type="submit"><i class="fa fa-search"></i></button> </form> </div> ``` CSS 代码: ```css .search-box { display: flex; justify-content: center; align-items: center; margin: 20px; } input[type="text"] { padding: 10px; border: none; border-radius: 5px 0 0 5px; width: 200px; font-size: 16px; } button[type="submit"] { padding: 10px 15px; background-color: #4CAF50; border: none; border-radius: 0 5px 5px 0; color: white; font-size: 16px; cursor: pointer; } i.fa.fa-search { font-size: 16px; margin-right: 5px; } ``` 这里的 HTML 代码中包含一个名为 `search-box` 的 div 元素,用于设置搜索框的样式。在 div 元素内部,使用了 form 元素和 input 元素来创建搜索框,使用了 button 元素和 i 元素来创建搜索按钮搜索图标。`placeholder` 属性提供了默认的提示文本,`name` 属性指定了提交的参数名称。 CSS 代码中使用了 `display: flex` 属性和 `justify-content: center` 和 `align-items: center` 属性来将搜索框水平居中。`border-radius` 属性用于设置输入框和按钮的圆角,`padding` 属性用于设置输入框和按钮的内边距,`width` 属性用于设置输入框的宽度。`background-color` 属性用于设置按钮的背景颜色,`color` 属性用于设置按钮的文字颜色,`cursor` 属性用于设置鼠标悬停时的光标类型。`fa` 和 `fa-search` 类名用于引用 Font Awesome 图标库中的搜索图标样式。 请注意,这里使用了 Font Awesome 图标库,您需要在页面中引入该库的 CSS 样式文件,例如: ```html <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值