Bootstrap4 教程
如果要自定義一個復選框,可以設置 <div> 為父元素,類為 .custom-control 和 .custom-checkbox,復選框作為子元素放在該 <div> 里頭,然后復選框設置為 type="checkbox",類為 .custom-control-input。
復選框的文本使用 label 標簽,標簽使用 .custom-control-label 類,label 的 for 屬性值需要匹配復選框的 id。
如果要自定義一個單選框,可以設置 <div> 為父元素,類為 .custom-control 和 .custom-radio,單選框作為子元素放在該 <div> 里頭,然后單選框設置為 type="radio",類為 .custom-control-input。
單選框的文本使用 label 標簽,標簽使用 .custom-control-label 類,label 的 for 屬性值需要匹配單選框的 id。
我們可以在外部元素上使用 .custom-control-inline 類來包裹自定義表單控件,這樣自定義表單控件就能顯示在同一行:
創(chuàng)建自定義選擇菜單可以在 <select> 元素上添加 .custom-select 類:
如果我們要設置自定義選擇菜單大小,可以使用 .custom-select-sm、.custom-select-lg 來設置它們的大小:
我們可以在 input 為 type="range" 的輸入框中添加 .custom-range 類來設置自定義滑塊控件:
我們可以在父元素添加 .custom-file 類,然后在 input 設置為 type="file" 并添加 .custom-file-input:
上傳控件的文本使用 label 標簽,標簽使用 .custom-file-label 類,label 的 for 屬性值需要匹配復選框的 id。