搜索按钮

创建于 2024-12-03 / 36
字体: [默认] [大] [更大]

了解如何使用 CSS 创建搜索按钮。


全宽:

Centered inside a form with max-width:

亲自试一试 »

如何创建搜索按钮

步骤 1) 添加 HTML:

实例

<!-- 加载图标库 -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<!-- The form -->
<form class="example" action="action_page.php">
  <input type="text" placeholder="Search.." name="search">
  <button type="submit"><i class="fa fa-search"></i></button>
</form>
步骤 2) 添加 CSS:

实例

* {
  box-sizing: border-box;
}

/* 为搜索字段设置样式 */
form.example input[type=text] {
  padding: 10px;
  font-size: 17px;
  border: 1px solid grey;
  float: left;
  width: 80%;
  background: #f1f1f1;
}

/* 设置提交按钮的样式 */
form.example button {
  float: left;
  width: 20%;
  padding: 10px;
  background: #2196F3;
  color: white;
  font-size: 17px;
  border: 1px solid grey;
  border-left: none; /* 防止双边框 */
  cursor: pointer;
}

form.example button:hover {
  background: #0b7dda;
}

/* 清除浮动 */
form.example::after {
  content: "";
  clear: both;
  display: table;
}
亲自试一试 »


0 人点赞过