css - 没有标签的引导自定义单选框未对齐
问题描述
我正在使用 Bootstrap4 自定义单选按钮,只要我使用标签文本,它就可以正常工作。有时有文本是没有意义的,但是单选按钮本身就是不对齐的。如何解决这个问题?
<div class="custom-control custom-radio">
<input type="radio" id="customRadio1" name="customRadio" class="custom-control-input">
<label class="custom-control-label" for="customRadio1"></label>
</div>
结果:
小提琴:https ://jsfiddle.net/SchweizerSchoggi/51vrL8px/5/
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<table class="table table-bordered">
<thead>
<th>Select</th>
<th>Name</th>
</thead>
<tr>
<td>
<div class="custom-control custom-radio">
<input type="radio" id="customRadio1" name="customRadio" class="custom-control-input">
<label class="custom-control-label" for="customRadio1"></label>
</div>
</td>
<td>Sample option 1</td>
</tr>
<tr>
<td>
<div class="custom-control custom-radio">
<input type="radio" id="customRadio1" name="customRadio" class="custom-control-input">
<label class="custom-control-label" for="customRadio1">with label</label>
</div>
</td>
<td>Sample option 2</td>
</tr>
</table>
解决方案
使用不打印任何内容的特殊字符可以让您获得正确的对齐方式,而不会在单选按钮旁边显示任何文本。
‌
我猜测它为什么会弄乱样式是因为添加到文本中的 ::before 和 ::after 代码。如果没有文本,则没有可添加标签的内容。
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
<table class="table table-bordered">
<thead>
<th>Select</th>
<th>Name</th>
</thead>
<tr>
<td>
<div class="custom-control custom-radio">
<input type="radio" id="customRadio1" name="customRadio" class="custom-control-input">
<label class="custom-control-label" for="customRadio1">‌</label>
</div>
</td>
<td>Sample option 1</td>
</tr>
<tr>
<td>
<div class="custom-control custom-radio">
<input type="radio" id="customRadio1" name="customRadio" class="custom-control-input">
<label class="custom-control-label" for="customRadio1">with label</label>
</div>
</td>
<td>Sample option 2</td>
</tr>
</table>
推荐阅读
- r - 日期范围输入问题。无法实现ggplot
- r - 更改列格式
- ios - Xcode 错误:无法设置()用户定义的已检查属性:此类与键的键值编码不兼容
- 3d - 获取 XYZ 点 3d 模型的 UV 纹理坐标
- r - 提取R中的最后一个数字及其尾随文本
- big-o - SICP对增长顺序的定义中提到的常数是什么?
- java - 如何将用户的提供商帐户存储在 Firebase 实时数据库中?
- rust - 将新函数名放入内部宏中
- swift - 如何修复 NSFetchedResultsController controllerDidChangeContent 中的内存泄漏
- android - 信号 11 (SIGSEGV),代码 1 (SEGV_MAPERR),故障地址 0x7d02bdb8