源代碼
點擊運行
<!DOCTYPE html> <html> <head> <title>Bootstrap 實例</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script> </head> <body> <div class="container mt-3"> <h2>自定義復選框</h2> <p>如果要自定義一個復選框,可以設置 <div> 為父元素,類為 .custom-control 和 .custom-checkbox,復選框作為子元素放在該 <div> 里頭,然後復選框設置為 type="checkbox",類為 .custom-control-input。</p> <p>復選框的文本使用 label 標籤,標籤使用 .custom-control-label 類,label 的 for 屬性值需要匹配復選框的 id。</p> <form action="/action_page.asp"> <div class="custom-control custom-checkbox mb-3"> <input type="checkbox" class="custom-control-input" id="customCheck" name="example1"> <label class="custom-control-label" for="customCheck">自定義復選框</label> </div> <input type="checkbox" id="defaultCheck" name="example2"> <label for="defaultCheck">默認復選框</label> <br> <button type="submit" class="btn btn-primary">提交</button> </form> </div> </body> </html>
運行結果