简体   繁体   English

嵌套在输入中时如何设置复选框的样式

[英]How to style a checkbox when it is nested within an input

Unlike the normal method of styling.... I have a Wordpress plugin that nests the input checkbox with the label.不同于一般的样式设置方法......我有一个 Wordpress 插件,它使用 label 嵌套输入复选框。

I'm 90% sure that I can't do this with CSS alone due to the parent-child relationship and I have tried and failed in that regard.由于父子关系,我 90% 确信我不能单独使用 CSS 做到这一点,我在这方面已经尝试过但失败了。 Markup I have is:我的标记是:

<label class="bundled_product_optional_checkbox">
<input class="bundled_product_checkbox" type="checkbox" name="bundle_selected_optional_1" value=""> 
Add for 
<span class="price">
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">£</span>30.00
</span>
<small class="woocommerce-price-suffix">ex. VAT</small>
</span>
</label>

I'd like a custom image for the checkmark and on checked.我想要一个用于复选标记和已选中的自定义图像。 Do I need to do this in CSS + js?我需要在 CSS + js 中执行此操作吗?

In your case, to look exactly the way you need it, I believe this JavaScript code will be the best solution for you:就您而言,要完全按照您的需要,我相信此 JavaScript 代码将是您的最佳解决方案:

<label class="bundled_product_optional_checkbox">
    <input class="bundled_product_checkbox" type="checkbox" name="bundle_selected_optional_1" value=""> 
    Add for 
    <span class="price">
        <span class="woocommerce-Price-amount amount">
            <span class="woocommerce-Price-currencySymbol">£</span>30.00
            </span>
        <small class="woocommerce-price-suffix">ex. VAT</small>
    </span>
    <
</label>

<style type="text/css">
    .bundled_product_optional_checkbox .bundled_product_checkbox{
        display: none;
    }
    .bundled_product_optional_checkbox .custom-checkbox{
        content: "";
        width: 20px;
        height: 20px;
        display: inline-block;
        border: 2px solid blue;
        position: left;
        border-radius: 5px;
    }
    .bundled_product_optional_checkbox .bundled_product_checkbox:checked + .custom-checkbox{
        background: blue;
    }
</style>

<script type="text/javascript">
    jQuery( function( $ ){
        $('.bundled_product_optional_checkbox .bundled_product_checkbox').after('<span class="custom-checkbox"></span>');
    } );
</script>

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

相关问题 标签标签包装复选框输入时如何删除复选框和样式标签 - How to remove checkbox, and style label, when label tag wraps checkbox input 如何使用输入type =复选框嵌套在标签class =“...”中来切换背景图像? - How to toggle between background images using input type = checkbox that is nested within label class=“…”? 如何设置 CSS 复选框的样式? - How to style a CSS checkbox? 输入为数字时如何使复选框为真 - How to make checkbox true when input is a number 如何从文本输入中的复选框选择中获取值 - How to get values from checkbox selections within a text input 如果我选中复选框,如何启用复选框中的输入? 因为当我选中输入类型的复选框时,它总是禁用 - How to enable the input in checkbox if i check the checkbox? cuz it always disable when i check the checkbox with input type 焦点对准时如何使用javascript设置(this)输入元素的样式 - How to style (this) input element with javascript when in focus 选中时创建一个复选框,该复选框应在模式中显示某些输入字段并隐藏其他输入字段 - Create a checkbox when checked it should show certain input fields & hide other input fields, within a Modal 嵌套ng-repeat中的复选框不可单击 - checkbox is not clickable within nested ng-repeat 如何设置角度的材质复选框? - How to style the material checkbox in angular ?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM