探索搜索框从基础布局到精美实现的完整过程
使用简单的HTML结构创建基本布局,顶部搜索框包含一个输入框和一个按钮,下方区域用于展示搜索关键字。 此阶段使用彩色区块可视化不同组件区域,明确基础结构。
<div class="search-box">
<div class="search-input"></div>
<div class="search-button"></div>
</div>
<div class="keywords-container">
<div class="keyword"></div>
<div class="keyword"></div>
<div class="keyword"></div>
</div>
为元素添加基本样式:设置输入框和按钮的尺寸与边框,定义关键字标签的内边距与背景色, 引入Flex布局实现响应式排列。添加简单悬停效果增强交互性。
.search-box {
display: flex;
height: 60px;
}
.search-input {
flex: 1;
padding: 10px 15px;
border-radius: 4px 0 0 4px;
background: #ff6b6b;
border: none;
}
.search-button {
width: 120px;
background: #4ECDC4;
border: none;
border-radius: 0 4px 4px 0;
}
.keyword {
background: #FFD166;
padding: 5px 12px;
border-radius: 4px;
cursor: pointer;
}
.keyword:hover {
opacity: 0.8;
}
完善视觉细节:添加阴影增强深度感,优化圆角创建现代外观,设置过渡效果实现平滑动画。 美化关键字标签为胶囊形状,优化按钮悬停效果提升用户体验。
.search-box {
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
border-radius: 8px;
overflow: hidden;
}
.search-input, .search-button {
transition: all 0.3s ease;
}
.search-button {
font-weight: bold;
cursor: pointer;
}
.search-button:hover {
transform: translateY(-2px);
box-shadow: inset 0 -4px 8px rgba(0,0,0,0.2);
}
.keyword {
border-radius: 30px;
padding: 8px 20px;
box-shadow: 0 3px 8px rgba(0,0,0,0.1);
font-weight: bold;
transition: transform 0.3s;
}
.keyword:hover {
transform: translateY(-3px);
box-shadow: 0 5px 15px rgba(0,0,0,0.2);
}
添加精致细节:输入框聚焦状态光晕效果,按钮渐变与细致阴影,关键字悬停动画。 优化字体与间距,添加内阴影增强输入区域深度感,整合所有过渡效果实现流畅交互体验。
.search-box {
display: flex;
height: 65px;
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.15);
border-radius: 12px;
overflow: hidden;
}
.search-input {
flex: 1;
padding: 20px 25px;
font-size: 1.2rem;
border: none;
background: #2d2d42;
color: white;
transition: all 0.3s ease;
box-shadow: inset 0 2px 4px rgba(0,0,0,0.4);
}
.search-input:focus {
outline: none;
background: #3a3a58;
box-shadow: inset 0 2px 8px rgba(0,0,0,0.6),
0 0 0 3px rgba(78, 205, 196, 0.3);
}
.search-button {
width: 120px;
background: #ff6b6b;
color: white;
border: none;
font-size: 1.1rem;
font-weight: bold;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: inset 0 -3px 8px rgba(0, 0, 0, 0.2);
}
.search-button:hover {
background: #ff5252;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(255, 107, 107, 0.4);
}
.keywords-container {
display: flex;
flex-wrap: wrap;
gap: 15px;
margin-top: 30px;
}
.keyword-tag {
background: #4ECDC4;
padding: 10px 25px;
border-radius: 30px;
font-size: 1.1rem;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
}
.keyword-tag:hover {
transform: translateY(-5px);
background: #2a9d8f;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}