如何在选择时使HTML单选按钮变为粗体? [英] How do you make an HTML Radio button bold on select?

查看:137
本文介绍了如何在选择时使HTML单选按钮变为粗体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HTML中,我有以下单选按钮选择:

o选择1

o选择2

o选择3



我想要做的是当某人从上面选择一个单选按钮时,对应于所选单选按钮的文本变为粗体。所以,例如 - 如果人选择选择2,单选按钮选择现在看起来像:

> o选择1

o选择2
$ b $选择3


我如何做到这一点?我假设要么使用JavaScript或CSS。



预先感谢

更新

strong>:您如何在不使用jQuery的情况下实现nickf解决方案?

解决方案

这纯粹与CSS,但你需要包裹每个输入的文本在一个跨度或其他标记:

 <输入类型=radioname =group1value =Milk>< span>牛奶< / span>< br> 

然后只需使用兄弟选择器:

  input [type =radio]:checked + span {font-weight:bold; } 


In HTML, I have the following radio button choices

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.

So, for example - if the person selects "Choice 2", the radio button selection would now look like:

o Choice 1
o Choice 2
o Choice 3

How do I do this? I assume either JavaScript or CSS has to be used.

Thanks in advance

UPDATE: How would you implement "nickf" solution without using jQuery?

解决方案

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单选按钮变为粗体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆