How do you make an HTML Radio button bold on select?(如何在选择时使 HTML 单选按钮变为粗体?)
问题描述
在 HTML 中,我有以下单选按钮选项
In HTML, I have the following radio button choices
o 选择 1
o 选择 2
o 选择 3
o Choice 1
o Choice 2
o Choice 3
我想要做的是,当有人从上方选择一个单选按钮时,与所选单选按钮对应的文本变为粗体.
What I would like to do is when someone SELECTs a radio button from above, that the text corresponding to that radio button selected becomes bold.
因此,例如 - 如果该人选择选择 2",则单选按钮选择现在看起来像:
So, for example - if the person selects "Choice 2", the radio button selection would now look like:
o 选择 1
o 选择 2
o 选择 3
o Choice 1
o Choice 2
o Choice 3
我该怎么做?我假设必须使用 JavaScript 或 CSS.
How do I do this? I assume either JavaScript or CSS has to be used.
提前致谢
更新:如果不使用 jQuery,你将如何实现nickf"解决方案?
推荐答案
你可以纯粹用 CSS 来做到这一点,但你需要将每个输入的文本包装在 span 或其他标签中:
You can do this purely with CSS, but you need to wrap the text of each input in a span or other tag:
<input type="radio" name="group1" value="Milk"><span>Milk</span><br>
然后只使用兄弟选择器:
Then just use the sibling selector:
input[type="radio"]:checked+span { font-weight: bold; }
这篇关于如何在选择时使 HTML 单选按钮变为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在选择时使 HTML 单选按钮变为粗体?


基础教程推荐
- 直接将值设置为滑块 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01