如何使用 CSS 创建动画搜索表单?

cssweb developmentfront end technology更新于 2025/10/5 18:20:17

以下代码使用 CSS 创建动画搜索表单 −

示例

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
*{
   box-sizing: border-box;
}
input[type=text] {
   width: 170px;
   font-size: 16px;
   background-color: white;
   padding: 12px 20px 12px 40px;
   transition: width 0.4s ease-in-out;
}
input[type=text]:focus {
   width: 100%;
}
</style>
</head>
<body>
<h1>Animated search form example</p>
<form>
Search:
<input type="text" name="search" placeholder="Search Here...">
</form>
</body>
</html>

输出

这将产生以下输出 −

点击搜索框时−


相关文章


有用资源