简体   繁体   English

单击单选按钮时如何突出显示标签?

[英]How can I highlight a label when click in a radio button?

I want to highlight the label of a radio button when a I click in it, I find an answer but don't work. 当我点击它时,我想要突出显示单选按钮的标签,我找到答案但不起作用。 Here my code: 这是我的代码:

HTML HTML

<div class="same-line">
    <input type="checkbox" name="417-jornadas-de-g%c3%a9nero-sin-fecha-confirmada" value="Sí" class="checkbox">
    <label class="checkbox">
    Jornadas de género (sin fecha confirmada)</label>
    <div class="clear-form"></div>
</div> 
<div class="same-line">
    <input type="checkbox" name="417-curso-de-fotograf%c3%ada-sin-fecha-confirmada" value="Sí" class="checkbox">
    <label class="checkbox">
    Curso de fotografía (sin fecha confirmada)</label>
    <div class="clear-form"></div>
</div>

CSS CSS

.same-line input[type='radio'] {
    display:none;
}

.same-line label[class='checkbox'] {
    display:inline-block;
        font-size: 12.2pt;
}

.same-line input[type='radio']:checked + label[class='checkbox'] { 
   background-color: #FFBF00 !important;
}

Any idea? 任何想法?

http://jsfiddle.net/hekh8/

input[type="radio"]:checked+label{ background-color: #FFFF00; } ​

HTML: HTML:

(I've added id attributes on the check-boxes, and for attributes on the labels) (我已经添加了id上的复选框的属性,以及for在标签属性)

<div class="same-line">
    <input type="checkbox" name="417-jornadas-de-g%c3%a9nero-sin-fecha-confirmada" id="cb1" value="Sí" class="checkbox">
    <label class="checkbox" for="cb1">
    Jornadas de género (sin fecha confirmada)</label>
    <div class="clear-form"></div>
</div>
<div class="same-line">
    <input type="checkbox" name="417-curso-de-fotograf%c3%ada-sin-fecha-confirmada" id="cb2" value="Sí" class="checkbox">
    <label class="checkbox" for="cb2">
    Curso de fotografía (sin fecha confirmada)</label>
    <div class="clear-form"></div>
</div>

CSS: CSS:

(I've changed "radio" to "checkbox") (我已将“收音机”改为“复选框”)

.same-line input[type='checkbox'] {
    display:none;
}

.same-line label.checkbox {
    display:inline-block;
        font-size: 12.2pt;
}

.same-line input[type='checkbox']:checked + label.checkbox { 
   background-color: #FFBF00;
}

Live demo: http://jsfiddle.net/PUcmA/1/ 现场演示: http //jsfiddle.net/PUcmA/1/

HTML : HTML

<div class="same-line">
    <input type="checkbox" id="checkbox1" name="417-jornadas-de-g%c3%a9nero-sin-fecha-confirmada" value="Sí" class="checkbox">
    <label for="checkbox1">
    Jornadas de género (sin fecha confirmada)</label>
    <div class="clear-form"></div>
</div> 
<div class="same-line">
    <input type="checkbox" id="checkbox2" name="417-curso-de-fotograf%c3%ada-sin-fecha-confirmada" value="Sí" class="checkbox">
    <label for="checkbox2">
    Curso de fotografía (sin fecha confirmada)</label>
    <div class="clear-form"></div>
</div>

CSS : CSS

.same-line input[type='checkbox'] {
    display:none;
}

.same-line label {
    display:inline-block;
        font-size: 12.2pt;
    background-color:#fff;
}

.same-line input[type='checkbox']:checked + label {
   background-color: #ddd;
}

jsFiddle: http://jsfiddle.net/heZBT/ jsFiddle: http//jsfiddle.net/heZBT/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在标签旁边有一个图标,当您单击该图标时,它不应单击该标签所附的标签/单选按钮 - I have an icon next to a label and when you click the icon, it should not click the label/radio button that the label is attached to 当我单击另一个单选按钮时,如何清除单选按钮选择中的内容? - How can I clear content from a radio button selection when I click on another radio button? 我如何在单击另一个单选按钮时禁用单选按钮 - how can i disable a radio button on click to another radio button 如何在单选按钮标签中添加文字? - How can I put text in a radio button label? 如何将单选按钮与下拉菜单和 label 对齐? - How can I align the radio button in a line to the dropdown and the label? 点击它后如何突出显示html页面中的按钮? - How to highlight a button in html page when i click on it? 单击单选按钮时如何更改背景颜色 - How can I change the background color when I click on a radio button 选择收音机并单击按钮时,如何运行功能? - How can I run a function when a radio is selected and I click a button? 使用Javascript更新单选按钮标签innerHTML后,如何防止单选按钮消失? - How can I prevent a radio button from disappearing after updating the radio button label innerHTML with Javascript? 单击单选按钮时如何更改音频标签? - How to change audio tag when I click on radio button?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM