[英]Show image based on input id or title through css
does anybody know how I can add an image before the label that is dependent on the input id or the title itself? 有谁知道如何在依赖于输入ID或标题本身的标签前添加图像? So this is from my magento checkout and I want to show an image based on the payment method. 这是我的magento结帐帐户,我想显示基于付款方式的图像。 This is the code 这是代码
<dt>
<input id="p_method_msp_ideal" value="msp_ideal" type="radio" name="payment[method]" title="iDEAL" class="radio validate-one-required-by-name">
<label for="p_method_msp_ideal">iDEAL</label>
</dt>
You could use a specific background image; 您可以使用特定的背景图片; it depends on your layout how this should be positioned and rendered, the below code is an example: 这取决于您的布局,该如何定位和呈现,以下代码为示例:
#p_method_msp_ideal + .payment-method{
width: 18px;
height: 12px;
background: url(images/ideal.png);
}
<dt>
<input id="p_method_msp_ideal" value="msp_ideal" type="radio" name="payment[method]" title="iDEAL" class="radio validate-one-required-by-name">
<span class="payment-method"></span>
<label for="p_method_msp_ideal">iDEAL</label>
</dt>
You could do this via psuedo elements, except that you can't place psuedo elements on an input. 您可以通过psuedo元素执行此操作,但不能将psuedo元素放置在输入中。
<dt>
<input id="p_method_msp_ideal" value="msp_ideal" type="radio" name="payment[method]" title="iDEAL" class="radio validate-one-required-by-name">
<label for="p_method_msp_ideal">iDEAL</label>
</dt>
It's a bit of an inefficient selector but this should work: 选择器效率低下,但这应该可以工作:
input[title="iDEAL"] + label:before {
content: "";
display: inline-block;
width: 18px;
height: 12px;
background: url(images/ideal.png);
}
Alternatively, if your for="p_method_msp_ideal"
is unique, use this instead of the sibling selector, or just generate a class name on the label based on the payment method. 另外,如果您的for="p_method_msp_ideal"
是唯一的,请使用它代替兄弟选择器,或者仅根据付款方式在标签上生成类名。
jsfiddle: http://jsfiddle.net/f1eLocoq/ jsfiddle: http : //jsfiddle.net/f1eLocoq/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.