วิธีสร้าง: ปุ่มค้นหา

เรียนรู้วิธีการสร้างปุ่มค้นหาด้วย CSS。

ความกว้างทั้งหมด

ตั้งตรงกลางฟอร์มที่มีความกว้างสูงสุด

亲自试一试

วิธีสร้างปุ่มค้นหา

ขั้นที่สาม - เพิ่ม HTML:

<!-- โหลดรายการภาพรวม -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- ฟอร์ม -->
<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>

ขั้นที่สอง - เพิ่ม 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;
{}

亲自试一试