html - Change overlapped image visibility on radio button click -
i want change visibility options 2 overlayed images radio buttons. .productbutton appears default, .productbutton_lower visibility: hidden. radio button becomes checked, .productbutton_lower becomes visible while .productbutton becomes hidden.
html
<strong>bottle size</strong><br/> <label class="prodbutt"> <input type="radio" class="size" value="10" name="size" required="required" /> <img src="http://i.imgur.com/vtmveab.png" class="productbutton" /> <img src="http://i.imgur.com/k9jvwfr.png" class="productbutton_lower" /> </label> <label class="prodbutt"> <input type="radio" class="size" value="30" name="size" required="required" /> <img src="http://i.imgur.com/kksv0wu.png" class="productbutton" /> <img src="http://i.imgur.com/40zkkjd.png" class="productbutton_lower" /> </label> <label class="prodbutt"> <input type="radio" class="size" value="100" name="size" required="required" /> <img src="http://i.imgur.com/seeigxt.png" class="productbutton" /> <img src="http://i.imgur.com/jbkhyi2.png" class="productbutton_lower" /> </label> css
label.prodbutt { position: relative; } img.productbutton { height: 25px; } img.productbutton_lower { height: 25px; visibility: hidden; position: absolute; bottom: 0; left: 0; } label.prodbutt > input[type="radio"] { visibility: hidden; position: absolute; } label.prodbutt > input[type="radio"]:checked + img.productbutton { visibility: hidden; } label.prodbutt > input[type="radio"]:checked + img.productbutton_lower { visibility: inline; } what wrong styling here, why won't .productbutton_lower become visible after radio button checked? additionally, forcing static visibility on .productbutton_lower gives odd positioning.
jsfiddle (as aside, how use so's inbuilt fiddle?)
two issues, (1) use general sibling selector ~ not +. (2) visibility:visible not inline.
label.prodbutt > input[type="radio"]:checked ~ img.productbutton { visibility: hidden; } label.prodbutt > input[type="radio"]:checked ~ img.productbutton_lower { visibility: visible; } https://jsfiddle.net/rsu264fc/2/
label.prodbutt { position: relative; } img.productbutton { height: 25px; } img.productbutton_lower { height: 25px; visibility: hidden; position: absolute; bottom: 0; left: 0; } label.prodbutt > input[type="radio"] { visibility: hidden; position: absolute; } label.prodbutt > input[type="radio"]:checked ~ img.productbutton { visibility: hidden; } label.prodbutt > input[type="radio"]:checked ~ img.productbutton_lower { visibility: visible; } <strong>bottle size</strong> <br/> <label class="prodbutt"> <input type="radio" class="size" value="10" name="size" required="required" /> <img src="http://i.imgur.com/vtmveab.png" class="productbutton" /> <img src="http://i.imgur.com/k9jvwfr.png" class="productbutton_lower" /> </label> <label class="prodbutt"> <input type="radio" class="size" value="30" name="size" required="required" /> <img src="http://i.imgur.com/kksv0wu.png" class="productbutton" /> <img src="http://i.imgur.com/40zkkjd.png" class="productbutton_lower" /> </label> <label class="prodbutt"> <input type="radio" class="size" value="100" name="size" required="required" /> <img src="http://i.imgur.com/seeigxt.png" class="productbutton" /> <img src="http://i.imgur.com/jbkhyi2.png" class="productbutton_lower" /> </label> explanations:
general sibling selectors ~ combinator separates 2 selectors , matches second element if preceded first, , both share common parent.
adjacent sibling selectors + select only specified element immediately follows former specified element.
lastly, visibility:inline not exist in css.
Comments
Post a Comment