简体   繁体   English

如何使用 css 在 bootstrap 内的表中设置复选框样式

[英]How to style checkbox inside table th td inside bootstrap using css

As with other solution using label and span but with bootstrap 4 it look not center in result with table tr td, how to center fit good:与其他使用标签和跨度但使用 bootstrap 4 的解决方案一样,它在表 tr td 的结果中看起来不居中,如何居中适合:

 span.bigcheck { font-family: sans-serif; font-weight: 500; font-size: 2em; } span.bigcheck-target { font-family: FontAwesome; /* Use an icon font for the checkbox */ } input[type='checkbox'].bigcheck { position: relative; left: -999em; /* Hide the real checkbox */ } input[type='checkbox'].bigcheck + span.bigcheck-target:after { content: "\f096"; /* In fontawesome, is an open square (fa-square-o) */ } input[type='checkbox'].bigcheck:checked + span.bigcheck-target:after { content: "\f046"; /* fontawesome checked box (fa-check-square-o) */ }
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> <table class='table table-sm tbl1 table-hover borderless font_fake' style='width:auto'> <thead> <tr> <th> <span class="bigcheck"> <label class="bigcheck"> <input type="checkbox" class="bigcheck" id="selectAll" /> <span class="bigcheck-target"></span> </label> </span> </th> <th>TH TITLE</th> </tr> </thead> <tbody> <tr> <td> <span class="bigcheck"> <label class="bigcheck"> <input type="checkbox" class="bigcheck" name="cheese" value="yes" /> <span class="bigcheck-target"></span> </label> </span> </td> <td>td desc 1</td> </tr> <tr> <td> <span class="bigcheck"> <label class="bigcheck"> <input type="checkbox" class="bigcheck" name="cheese" value="yes" /> <span class="bigcheck-target"></span> </label> </span> </td> <td>td desc 2</td> </tr> <tr> <td> <span class="bigcheck"> <label class="bigcheck"> <input type="checkbox" class="bigcheck" name="cheese" value="yes" /> <span class="bigcheck-target"></span> </label> </span> </td> <td>td desc 3</td> </tr> </tbody> </table>

As see at code above the result put checkbox not fit into th td.如上面的代码所示,结果 put checkbox not fit into th td。 How to make check box fit inside th look nice and fit into td also.如何使复选框适合内部 th 看起来不错,也适合 td。 I was try using margin:0 and padding:0 Bootstrap 4 @label Bootstrap 4 @span我尝试使用 margin:0 和 padding:0 Bootstrap 4 @label Bootstrap 4 @span

Thanks for advance.感谢您的提前。

I set vertical-align: middle;我设置vertical-align: middle; to td and th which are by default vertical-align: top;tdth ,它们默认为vertical-align: top; and second set the height of checkbox然后设置checkboxheight

 span.bigcheck { font-family: sans-serif; font-weight: 500; font-size: 2em; display: inline-block; height: 36px; } span.bigcheck-target { font-family: FontAwesome; /* Use an icon font for the checkbox */ } input[type='checkbox'].bigcheck { position: relative; left: -999em; /* Hide the real checkbox */ } input[type='checkbox'].bigcheck + span.bigcheck-target:after { content: "\f096"; /* In fontawesome, is an open square (fa-square-o) */ } input[type='checkbox'].bigcheck:checked + span.bigcheck-target:after { content: "\f046"; /* fontawesome checked box (fa-check-square-o) */ } table tr td,table tr th{ vertical-align: middle;important; }
 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"> <table class='table table-sm tbl1 table-hover borderless font_fake' style='width:auto'> <thead> <tr> <th> <span class="bigcheck"> <label class="bigcheck"> <input type="checkbox" class="bigcheck" id="selectAll" /> <span class="bigcheck-target"></span> </label> </span> </th> <th>TH TITLE</th> </tr> </thead> <tbody> <tr> <td> <span class="bigcheck"> <label class="bigcheck"> <input type="checkbox" class="bigcheck" name="cheese" value="yes" /> <span class="bigcheck-target"></span> </label> </span> </td> <td>td desc 1</td> </tr> <tr> <td> <span class="bigcheck"> <label class="bigcheck"> <input type="checkbox" class="bigcheck" name="cheese" value="yes" /> <span class="bigcheck-target"></span> </label> </span> </td> <td>td desc 2</td> </tr> <tr> <td> <span class="bigcheck"> <label class="bigcheck"> <input type="checkbox" class="bigcheck" name="cheese" value="yes" /> <span class="bigcheck-target"></span> </label> </span> </td> <td>td desc 3</td> </tr> </tbody> </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM