源代碼
點擊運行
<!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-radio,復選框作為子元素放在該 div 里頭,然後單選框設置為 type="radio",類為 .custom-control-input。</p> <p>單選框的文本使用 label 標籤,標籤使用 .custom-control-label 類,label 的 for 屬性值需要匹配單選框的 id。</p> <form action="/action_page.asp"> <div class="custom-control custom-radio"> <input type="radio" class="custom-control-input" id="customRadio" name="example1"> <label class="custom-control-label" for="customRadio">自定義單選框</label> </div> <input type="radio" id="defaultRadio" name="example2"> <label for="defaultRadio">默認單選框</label> <br> <button type="submit" class="btn btn-primary">提交</button> </form> </div> </body> </html>
運行結果