今天我们来学习如何使用CSS建立一个搜索框。首先,我们需要在HTML文档中创建一个搜索框的输入框以及按钮:
<form><input type="text" placeholder="Search"><button type="submit">Go</button></form>
我们可以使用CSS样式来美化搜索框的输入框和按钮的样式。为了使搜索框居中以及便于在后续的代码中使用,我们可以使用CSS将其放在一个div标签中:
<div ><form><input type="text" placeholder="Search"><button type="submit">Go</button></form></div>
现在,我们可以开始美化搜索框的样式了。首先,我们可以设置搜索框输入框的边框样式、背景颜色和圆角等样式:
.search-box input[type="text"] {border: none;background-color: #f2f2f2;border-radius: 20px;padding: 10px;width: 250px;box-shadow: none;}
接下来,我们可以为搜索框按钮设置样式。我们可以使用CSS来设置按钮的边框、背景颜色和圆角等样式:
.search-box button[type="submit"] {border: none;background-color: #4CAF50;color: white;padding: 10px;border-radius: 20px;cursor: pointer;box-shadow: none;}
最后,我们可以使用CSS将搜索框居中。我们可以为搜索框的父级元素设置text-align样式即可:
.search-box {text-align: center;}
现在,我们的搜索框就完成了!你可以尝试在你的网页中添加搜索框啦!