css制作搜索
CSS 制作搜索框的方法
基础搜索框样式
.search-box {
width: 300px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 20px;
outline: none;
font-size: 16px;
}
添加图标搜索框

<div class="search-container">
<input type="text" placeholder="搜索..." class="search-input">
<button class="search-button">
<i class="fas fa-search"></i>
</button>
</div>
.search-container {
display: flex;
width: 300px;
}
.search-input {
flex: 1;
padding: 10px;
border: 1px solid #ccc;
border-right: none;
border-radius: 20px 0 0 20px;
outline: none;
}
.search-button {
width: 40px;
background: #4CAF50;
color: white;
border: none;
border-radius: 0 20px 20px 0;
cursor: pointer;
}
动画效果搜索框

.search-box {
transition: all 0.3s ease;
}
.search-box:focus {
width: 350px;
box-shadow: 0 0 5px rgba(81, 203, 238, 1);
}
响应式搜索框
@media (max-width: 768px) {
.search-box {
width: 100%;
}
}
高级搜索建议框
.search-suggestions {
position: absolute;
width: 300px;
background: white;
border: 1px solid #ddd;
max-height: 200px;
overflow-y: auto;
display: none;
}
.search-suggestions.show {
display: block;
}
.suggestion-item {
padding: 8px 12px;
cursor: pointer;
}
.suggestion-item:hover {
background: #f5f5f5;
}
这些CSS方法可以单独使用或组合使用,根据具体需求创建不同风格的搜索框。对于更复杂的功能,通常需要配合JavaScript实现交互逻辑。






