[英]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.