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 单选按钮变为粗体?
基础教程推荐
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
