css搜索框制作
CSS 搜索框制作方法
基础搜索框样式 使用 HTML 和 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 #ccc;
border-radius: 4px 0 0 4px;
outline: none;
}
.search-box button {
padding: 10px 15px;
background-color: #007bff;
color: white;
border: none;
border-radius: 0 4px 4px 0;
cursor: pointer;
}
带图标搜索框 使用 Font Awesome 图标库添加搜索图标。
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<div class="search-box">
<input type="text" placeholder="搜索...">
<button><i class="fas fa-search"></i></button>
</div>
圆角搜索框 创建完全圆角的搜索框样式。
.search-box input {
border-radius: 20px 0 0 20px;
}
.search-box button {
border-radius: 0 20px 20px 0;
}
悬浮效果 为搜索框添加悬浮时的交互效果。
.search-box input:focus {
border-color: #007bff;
}
.search-box button:hover {
background-color: #0056b3;
}
响应式搜索框 使搜索框在不同屏幕尺寸下自适应。
@media (max-width: 600px) {
.search-box {
width: 90%;
}
}
高级动画效果 为搜索框添加展开动画。
.search-box {
transition: all 0.3s ease;
}
.search-box:focus-within {
transform: scale(1.05);
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
透明玻璃效果 使用 backdrop-filter 创建磨砂玻璃效果。
.search-box {
background-color: rgba(255, 255, 255, 0.2);
backdrop-filter: blur(10px);
border-radius: 20px;
padding: 5px;
}
夜间模式支持 添加 prefers-color-scheme 媒体查询支持暗黑模式。

@media (prefers-color-scheme: dark) {
.search-box input {
background-color: #333;
color: white;
border-color: #555;
}
}






