html - 当单选按钮被选中时如何设置粗体标签

标签 html css

为什么此设置下标签不是粗体?

      <form class="input-group">
<div class="btn-section-operation" id="btn-container-table">
    <label for="radio-selection-range-rows" class="radio-custom-label"><input class="radio-custom input-group-field" id="radio-selection-range-rows" name="radio-selection" type="radio" checked="checked">Rows</label>
    <label for="radio-selection-range-rel" class="radio-custom-label"><input class="radio-custom input-group-field" id="radio-selection-range-rel" name="radio-selection" type="radio">Rows with relations</label>
</div>

Codepen

最佳答案

您不应该使用label:checked ,但是input:checked对于选中的复选框。此外,您使用同级选择器,但您想要设置样式的元素是父元素(标签是输入的父元素)。 CSS 中没有父选择器,所以我的解决方案是使用 span围绕文本。

<label for="radio-selection-range-rows" class="radio-custom-label">
    <input class="radio-custom input-group-field" id="radio-selection-range-rows" name="radio-selection" type="radio" checked="checked">
    <span>Rows</span>
</label>

然后像这样选择:

input:checked ~ span {
    border-color: black;
    font-weight: bold;
}

您还可以输入 outside label并使用其他CSS,但你可能有理由这样做。

关于html - 当单选按钮被选中时如何设置粗体标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54801132/

相关文章:

css - 更改 CCS 色带代码/样式

html - 样式生成的表格行

html - 使用angular6显示多个嵌套数据

javascript - 使用 Angular 1 Interpolation 将动态值传递给函数参数

iphone - 如何禁用水平拖动? (webkit-溢出-滚动 : touch;)

html - 页眉长于页面

javascript - 在 html 标签之外渲染 Vue.js @click 指令

html - 如何将导航栏品牌放在 twitter bootstrap 的右侧?

html - 无法将我的文本定位在用 CSS 制作的圆圈中

html - 元素不会在 IE7 中停滞不前