制作css搜索页面
设计CSS搜索页面布局
使用Flexbox或Grid布局创建响应式搜索页面结构。Flexbox适合简单的一维布局,Grid适合复杂的二维布局。搜索框通常居中显示,搭配适当的留白和视觉层次。
.search-container {
display: flex;
justify-content: center;
padding: 2rem;
}
.search-box {
width: 100%;
max-width: 600px;
}
设计搜索输入框样式
自定义输入框外观,包括边框、阴影和过渡效果。使用伪类(:focus)突出显示激活状态,圆角边框增强现代感。
.search-input {
width: 100%;
padding: 12px 20px;
border: 2px solid #ddd;
border-radius: 30px;
font-size: 16px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
transition: all 0.3s ease;
}
.search-input:focus {
border-color: #4285f4;
box-shadow: 0 2px 10px rgba(66, 133, 244, 0.2);
outline: none;
}
添加搜索按钮样式
创建视觉上协调的搜索按钮,可以使用图标字体或SVG图标。按钮悬停效果增强交互反馈。
.search-button {
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
color: #555;
cursor: pointer;
font-size: 18px;
}
.search-button:hover {
color: #4285f4;
}
实现搜索建议下拉框
为自动完成功能设计下拉建议列表样式。使用绝对定位确保列表出现在输入框下方,添加悬停高亮效果。
.suggestions-list {
position: absolute;
width: 100%;
max-width: 600px;
background: white;
border: 1px solid #eee;
border-radius: 0 0 8px 8px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
z-index: 100;
}
.suggestion-item {
padding: 10px 20px;
cursor: pointer;
}
.suggestion-item:hover {
background-color: #f5f5f5;
}
添加加载动画效果
使用CSS动画创建搜索过程中的加载指示器。旋转动画或进度条增强用户体验。
.loading-spinner {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid rgba(0,0,0,0.1);
border-radius: 50%;
border-top-color: #4285f4;
animation: spin 1s ease-in-out infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
响应式设计调整
针对不同屏幕尺寸优化搜索页面布局。移动设备上调整输入框大小和间距。

@media (max-width: 768px) {
.search-container {
padding: 1rem;
}
.search-input {
padding: 10px 15px;
font-size: 14px;
}
}






