Hướng dẫn bootstrap 5 search box with icon - hộp tìm kiếm bootstrap 5 có biểu tượng

Thêm nhận xét/câu hỏi

Nhập thêm 15 ký tự

Show

Tìm hiểu, phát triển và giúp đỡ người khác với BBBOOTSTRAP

Đóng góp cho chúng tôi với một số đoạn trích thú vị tuyệt vời sử dụng HTML, CSS, JavaScript và Bootstrap

Đầu vào hộp tìm kiếm Bootstrap 5 với các biểu tượng bên trong đoạn trích được tạo bởi nhóm BBBOOTSTRAP bằng bootstrap 5. Đoạn trích này là miễn phí và nguồn mở do đó bạn có thể sử dụng nó trong dự án của mình. Dự án

Thành phần tìm kiếm bootstrap 5

Hộp tìm kiếm là một phần tử UI được chuẩn bị để tạo các công cụ tìm kiếm. Phần tử quan trọng nhất của nó là đầu vào tìm kiếm, nhưng nó cũng có thể chứa các biểu tượng hoặc nút. Nó cũng được điều chỉnh để được sử dụng trong các thành phần khác như Navbar, thả xuống, bảng, chọn, sidenav và nhiều thành phần khác.


Ví dụ cơ bản

Một ví dụ cơ bản với một nút đơn giản.


Biến thể

Tìm kiếm đi kèm với nhiều biến thể. Chọn từ những điều sau khi cần thiết:

  • Tìm kiếm với biểu tượng
  • Tìm kiếm bằng nút
  • Tìm kiếm mà không cần thêm các yếu tố

Tìm kiếm với biểu tượng

Tìm kiếm bằng nút


Tìm kiếm bằng nút

Tìm kiếm mà không cần thêm các yếu tố


Tìm kiếm mà không cần thêm các yếu tố

Xem tất cả các biểu tượng có sẵn trong tài liệu biểu tượng.


Xem tất cả các kết hợp đầu vào có thể có trong các tài liệu nhóm đầu vào.

Dưới đây là một ví dụ về cách bạn có thể tạo thành phần tìm kiếm mà không có bất kỳ phần tử nào được đính kèm:


Sự kiện tìm kiếm

Dưới đây là ví dụ làm thế nào bạn có thể tạo thành phần tìm kiếm với sự kiện trên đó sẽ bắn sau khi nhấp vào nút tìm kiếm.

Tự động hoàn thành


Bằng cách thêm mã JS bổ sung, bạn cũng có thể thực hiện đầu vào tìm kiếm của mình tự động hoàn thành.

Tìm hiểu thêm về tự động hoàn thành trong tài liệu tự động hoàn chỉnh


Tiêu điểm

Bạn có thể làm cho đầu vào của mình trong thành phần tìm kiếm có thể tập trung bằng cách nhấn phím tắt

<div class="input-group flex-nowrap">
  <span class="input-group-text" id="addon-wrapping">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
div>
2 +
<div class="input-group flex-nowrap">
  <span class="input-group-text" id="addon-wrapping">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
div>
3. Bạn có thể dễ dàng thay đổi kết hợp các phím tắt bằng cách sửa đổi mảng
<div class="input-group flex-nowrap">
  <span class="input-group-text" id="addon-wrapping">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
div>
4 trong mã JS. Ví dụ: để thay đổi
<div class="input-group flex-nowrap">
  <span class="input-group-text" id="addon-wrapping">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
div>
5 thành khóa
<div class="input-group flex-nowrap">
  <span class="input-group-text" id="addon-wrapping">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
div>
6 Chỉ cần trao đổi nó thành
<div class="input-group flex-nowrap">
  <span class="input-group-text" id="addon-wrapping">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
div>
7, v.v.

Thanh điều khiển


Tìm kiếm dễ dàng được tích hợp với nhiều thành phần của chúng tôi như Navbar.

Tìm hiểu thêm về Navbar trong tài liệu Navbar

Thả xuống


Hơn nữa, bạn có thể tích hợp tìm kiếm của chúng tôi với thành phần thả xuống

Tìm hiểu thêm về thả xuống trong các tài liệu thả xuống

Bảng dữ liệu


Nó hoạt động hoàn hảo với MDB DataTables.

Tìm hiểu thêm về DataTables trong tài liệu DataTables

Lựa chọn


Bạn cũng có thể tìm thấy tùy chọn tìm kiếm trong chọn đầu vào bằng cách thêm vào chọn thuộc tính
@
8

Tìm hiểu thêm về Chọn trong các tài liệu chọn

Sidenav


Ví dụ cơ bản

Đặt một nút bổ trợ hoặc nút ở hai bên của đầu vào. Bạn cũng có thể đặt một ở cả hai bên của đầu vào. Hãy nhớ đặt

<div class="input-group flex-nowrap">
  <span class="input-group-text" id="addon-wrapping">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
div>
9s bên ngoài nhóm đầu vào.

@

@example.com

Url vanity của bạn

https://example.com/users/

$.00 .00

@

Url vanity của bạn

<div class="input-group mb-3">
  <span class="input-group-text" id="basic-addon1">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
div>

<div class="input-group mb-3">
  <input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="basic-addon2">
  <span class="input-group-text" id="basic-addon2">@example.comspan>
div>

<label for="basic-url" class="form-label">Your vanity URLlabel>
<div class="input-group mb-3">
  <span class="input-group-text" id="basic-addon3">https://example.com/users/span>
  <input type="text" class="form-control" id="basic-url" aria-describedby="basic-addon3">
div>

<div class="input-group mb-3">
  <span class="input-group-text">$span>
  <input type="text" class="form-control" aria-label="Amount (to the nearest dollar)">
  <span class="input-group-text">.00span>
div>

<div class="input-group mb-3">
  <input type="text" class="form-control" placeholder="Username" aria-label="Username">
  <span class="input-group-text">@span>
  <input type="text" class="form-control" placeholder="Server" aria-label="Server">
div>

<div class="input-group">
  <span class="input-group-text">With textareaspan>
  <textarea class="form-control" aria-label="With textarea">textarea>
div>

Với Textarea

Gói

<div class="input-group flex-nowrap">
  <span class="input-group-text" id="addon-wrapping">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
div>

Các nhóm đầu vào bọc theo mặc định qua
Small
Default
Large
0 để phù hợp với xác thực trường biểu mẫu tùy chỉnh trong một nhóm đầu vào. Bạn có thể vô hiệu hóa điều này với
Small
Default
Large
1.

Kích thước

Thêm các lớp kích thước biểu mẫu tương đối vào chính

<div class="input-group input-group-sm mb-3">
  <span class="input-group-text" id="inputGroup-sizing-sm">Smallspan>
  <input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
div>

<div class="input-group mb-3">
  <span class="input-group-text" id="inputGroup-sizing-default">Defaultspan>
  <input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
div>

<div class="input-group input-group-lg">
  <span class="input-group-text" id="inputGroup-sizing-lg">Largespan>
  <input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-lg">
div>
2 và nội dung bên trong sẽ tự động thay đổi kích thước không cần phải lặp lại các lớp kích thước điều khiển biểu mẫu trên mỗi phần tử.

<div class="input-group input-group-sm mb-3">
  <span class="input-group-text" id="inputGroup-sizing-sm">Smallspan>
  <input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-sm">
div>

<div class="input-group mb-3">
  <span class="input-group-text" id="inputGroup-sizing-default">Defaultspan>
  <input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-default">
div>

<div class="input-group input-group-lg">
  <span class="input-group-text" id="inputGroup-sizing-lg">Largespan>
  <input type="text" class="form-control" aria-label="Sizing example input" aria-describedby="inputGroup-sizing-lg">
div>

Kích thước trên các yếu tố nhóm đầu vào cá nhân không được hỗ trợ.

Hộp kiểm và radio

<div class="input-group mb-3">
  <div class="input-group-text">
    <input class="form-check-input mt-0" type="checkbox" value="" aria-label="Checkbox for following text input">
  div>
  <input type="text" class="form-control" aria-label="Text input with checkbox">
div>

<div class="input-group">
  <div class="input-group-text">
    <input class="form-check-input mt-0" type="radio" value="" aria-label="Radio button for following text input">
  div>
  <input type="text" class="form-control" aria-label="Text input with radio button">
div>

Đặt bất kỳ hộp kiểm hoặc tùy chọn radio nào trong nhóm đầu vào addon thay vì văn bản. Chúng tôi khuyên bạn nên thêm
Small
Default
Large
3 vào
Small
Default
Large
4 khi không có văn bản có thể nhìn thấy bên cạnh đầu vào.

Nhiều đầu vào

<div class="input-group">
  <span class="input-group-text">First and last namespan>
  <input type="text" aria-label="First name" class="form-control">
  <input type="text" aria-label="Last name" class="form-control">
div>

Trong khi nhiều
Small
Default
Large
5 được hỗ trợ trực quan, các kiểu xác thực chỉ có sẵn cho các nhóm đầu vào với một
Small
Default
Large
5.

Nhiều addons

<div class="input-group mb-3">
  <span class="input-group-text">$span>
  <span class="input-group-text">0.00span>
  <input type="text" class="form-control" aria-label="Dollar amount (with dot and two decimal places)">
div>

<div class="input-group">
  <input type="text" class="form-control" aria-label="Dollar amount (with dot and two decimal places)">
  <span class="input-group-text">$span>
  <span class="input-group-text">0.00span>
div>

Nhiều tiện ích bổ sung được hỗ trợ và có thể được trộn với các phiên bản đầu vào hộp kiểm và radio.

<div class="input-group mb-3">
  <button class="btn btn-outline-secondary" type="button" id="button-addon1">Buttonbutton>
  <input type="text" class="form-control" placeholder="" aria-label="Example text with button addon" aria-describedby="button-addon1">
div>

<div class="input-group mb-3">
  <input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="button-addon2">
  <button class="btn btn-outline-secondary" type="button" id="button-addon2">Buttonbutton>
div>

<div class="input-group mb-3">
  <button class="btn btn-outline-secondary" type="button">Buttonbutton>
  <button class="btn btn-outline-secondary" type="button">Buttonbutton>
  <input type="text" class="form-control" placeholder="" aria-label="Example text with two button addons">
div>

<div class="input-group">
  <input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username with two button addons">
  <button class="btn btn-outline-secondary" type="button">Buttonbutton>
  <button class="btn btn-outline-secondary" type="button">Buttonbutton>
div>

Addons nút

<div class="input-group mb-3">
  <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdownbutton>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">Actiona>li>
    <li><a class="dropdown-item" href="#">Another actiona>li>
    <li><a class="dropdown-item" href="#">Something else herea>li>
    <li><hr class="dropdown-divider">li>
    <li><a class="dropdown-item" href="#">Separated linka>li>
  ul>
  <input type="text" class="form-control" aria-label="Text input with dropdown button">
div>

<div class="input-group mb-3">
  <input type="text" class="form-control" aria-label="Text input with dropdown button">
  <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdownbutton>
  <ul class="dropdown-menu dropdown-menu-end">
    <li><a class="dropdown-item" href="#">Actiona>li>
    <li><a class="dropdown-item" href="#">Another actiona>li>
    <li><a class="dropdown-item" href="#">Something else herea>li>
    <li><hr class="dropdown-divider">li>
    <li><a class="dropdown-item" href="#">Separated linka>li>
  ul>
div>

<div class="input-group">
  <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdownbutton>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">Action beforea>li>
    <li><a class="dropdown-item" href="#">Another action beforea>li>
    <li><a class="dropdown-item" href="#">Something else herea>li>
    <li><hr class="dropdown-divider">li>
    <li><a class="dropdown-item" href="#">Separated linka>li>
  ul>
  <input type="text" class="form-control" aria-label="Text input with 2 dropdown buttons">
  <button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">Dropdownbutton>
  <ul class="dropdown-menu dropdown-menu-end">
    <li><a class="dropdown-item" href="#">Actiona>li>
    <li><a class="dropdown-item" href="#">Another actiona>li>
    <li><a class="dropdown-item" href="#">Something else herea>li>
    <li><hr class="dropdown-divider">li>
    <li><a class="dropdown-item" href="#">Separated linka>li>
  ul>
div>

Các nút có thả xuống

<div class="input-group mb-3">
  <button type="button" class="btn btn-outline-secondary">Actionbutton>
  <button type="button" class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
    <span class="visually-hidden">Toggle Dropdownspan>
  button>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="#">Actiona>li>
    <li><a class="dropdown-item" href="#">Another actiona>li>
    <li><a class="dropdown-item" href="#">Something else herea>li>
    <li><hr class="dropdown-divider">li>
    <li><a class="dropdown-item" href="#">Separated linka>li>
  ul>
  <input type="text" class="form-control" aria-label="Text input with segmented dropdown button">
div>

<div class="input-group">
  <input type="text" class="form-control" aria-label="Text input with segmented dropdown button">
  <button type="button" class="btn btn-outline-secondary">Actionbutton>
  <button type="button" class="btn btn-outline-secondary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
    <span class="visually-hidden">Toggle Dropdownspan>
  button>
  <ul class="dropdown-menu dropdown-menu-end">
    <li><a class="dropdown-item" href="#">Actiona>li>
    <li><a class="dropdown-item" href="#">Another actiona>li>
    <li><a class="dropdown-item" href="#">Something else herea>li>
    <li><hr class="dropdown-divider">li>
    <li><a class="dropdown-item" href="#">Separated linka>li>
  ul>
div>

Các nút phân đoạn

Hình thức tùy chỉnh

Tùy chỉnh chọn

<div class="input-group mb-3">
  <label class="input-group-text" for="inputGroupSelect01">Optionslabel>
  <select class="form-select" id="inputGroupSelect01">
    <option selected>Choose...option>
    <option value="1">Oneoption>
    <option value="2">Twooption>
    <option value="3">Threeoption>
  select>
div>

<div class="input-group mb-3">
  <select class="form-select" id="inputGroupSelect02">
    <option selected>Choose...option>
    <option value="1">Oneoption>
    <option value="2">Twooption>
    <option value="3">Threeoption>
  select>
  <label class="input-group-text" for="inputGroupSelect02">Optionslabel>
div>

<div class="input-group mb-3">
  <button class="btn btn-outline-secondary" type="button">Buttonbutton>
  <select class="form-select" id="inputGroupSelect03" aria-label="Example select with button addon">
    <option selected>Choose...option>
    <option value="1">Oneoption>
    <option value="2">Twooption>
    <option value="3">Threeoption>
  select>
div>

<div class="input-group">
  <select class="form-select" id="inputGroupSelect04" aria-label="Example select with button addon">
    <option selected>Choose...option>
    <option value="1">Oneoption>
    <option value="2">Twooption>
    <option value="3">Threeoption>
  select>
  <button class="btn btn-outline-secondary" type="button">Buttonbutton>
div>

Đầu vào tập tin tùy chỉnh

<div class="input-group flex-nowrap">
  <span class="input-group-text" id="addon-wrapping">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
div>
0

Sass

Biến

<div class="input-group flex-nowrap">
  <span class="input-group-text" id="addon-wrapping">@span>
  <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="addon-wrapping">
div>
1

Làm thế nào bạn có thể chèn biểu tượng tìm kiếm trong Bootstrap 5?

Hướng dẫn từng bước để thực hiện: Bước 1: Bao gồm Bootstrap và jQuery CDN vào thẻ trước tất cả các bảng kiểu khác để tải CSS của chúng tôi. Bước 2: Thêm thẻ trong thân HTML với thùng chứa lớp. Bước 3: Bây giờ thêm bất kỳ biểu tượng nào bạn muốn sử dụng cú pháp dưới đây, trong đó tên là tên của Glyphicon.Step 1: Include Bootstrap and jQuery CDN into the tag before all other stylesheets to load our CSS. Step 2: Add
tag in the HTML body with class container. Step 3: Now add any icon that you want using the below syntax, where the name is the name of glyphicon.

Làm cách nào để thêm biểu tượng tìm kiếm vào hộp đầu vào của tôi?

Để thêm biểu tượng bên trong phần tử đầu vào, thẻ và thẻ được sử dụng rộng rãi để thêm các biểu tượng trên các trang web.Để thêm bất kỳ biểu tượng nào trên các trang web hoặc trong một số khu vực cụ thể, nó cần liên kết Fontawgie bên trong thẻ đầu.Biểu tượng fontawie có thể được đặt bằng cách sử dụng tiền tố FA trước tên biểu tượng.the tag and tag are used widely to add icons on the webpages. To add any icons on the webpages or in some specific area, it needs the fontawesome link inside the head tag. The fontawesome icon can be placed by using the fa prefix before the icon's name.

Tôi có thể sử dụng glyphicons trong bootstrap 5 không?

Glyphicons Halflings thường không có sẵn miễn phí, nhưng người tạo ra của họ đã cung cấp cho họ cho bootstrap miễn phí.Như một lời cảm ơn, chúng tôi chỉ yêu cầu bạn bao gồm một liên kết trở lại glyphicons bất cứ khi nào có thể.their creator has made them available for Bootstrap free of cost. As a thank you, we only ask that you include a link back to Glyphicons whenever possible.

Làm cách nào để thêm biểu tượng tìm kiếm bên trong hộp văn bản trong HTML?

Trong HTML, các biểu tượng được thêm vào với thẻ.Để nó được thêm vào bên trong các phần tử đầu vào, nó phải được thêm vào giữa các thẻ đóng và mở của các phần tử mà bạn muốn biểu tượng được hiển thị.it must be added between the closing and opening tags of the elements in which you want the icon to be displayed.