css制作搜索框
使用CSS制作搜索框
基础搜索框样式
创建一个简单的搜索框,包含输入框和搜索按钮:
<div class="search-box">
<input type="text" placeholder="搜索...">
<button>搜索</button>
</div>
.search-box {
display: flex;
width: 300px;
margin: 20px auto;
}
.search-box input {
flex: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px 0 0 4px;
outline: none;
}
.search-box button {
padding: 10px 15px;
background: #4285f4;
color: white;
border: none;
border-radius: 0 4px 4px 0;
cursor: pointer;
}
.search-box button:hover {
background: #3367d6;
}
圆角搜索框
创建全圆角的搜索框样式:

.search-box input {
border-radius: 20px 0 0 20px;
padding-left: 15px;
}
.search-box button {
border-radius: 0 20px 20px 0;
}
图标搜索框
使用字体图标代替文字按钮:
<div class="search-box">
<input type="text" placeholder="搜索...">
<button><i class="fas fa-search"></i></button>
</div>
.search-box button {
width: 40px;
padding: 10px;
}
动画效果搜索框
添加展开动画效果:

.search-box input {
transition: all 0.3s ease;
width: 0;
padding: 10px 0;
}
.search-box:hover input,
.search-box input:focus {
width: 200px;
padding: 10px;
}
透明玻璃效果
创建毛玻璃效果的搜索框:
.search-box {
background: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 5px;
}
.search-box input {
background: transparent;
border: none;
color: white;
}
.search-box input::placeholder {
color: rgba(255, 255, 255, 0.7);
}
响应式搜索框
使搜索框在不同屏幕尺寸下自适应:
.search-box {
max-width: 500px;
width: 90%;
}
@media (min-width: 768px) {
.search-box {
width: 70%;
}
}
这些CSS样式可以根据实际需求组合使用,创建出各种风格的搜索框。通过调整颜色、边框、阴影等属性,可以进一步定制搜索框的外观。






