我可以使用 ony css 显示或隐藏内容吗?隐藏或显示的内容取决于选中或取消选中表单框吗?
或者我需要 javascript 吗?
感谢您的见解!!
最佳答案
是的,通过使用“相邻兄弟”选择器 (+
) 和 checked
伪类。
HTML
<label>Box 1: <input type="checkbox"><span>Box 1 is checked.</span></label>
<label>Box 2: <input type="checkbox"><span>Box 2 is checked.</span></label>
<label>Box 3: <input type="checkbox"><span>Box 3 is checked.</span></label>
CSS
label {display:block;}
input[type="checkbox"] + * {display:none; margin-left:1em;}
input[type="checkbox"]:checked + * {display:inline;}
关于javascript - 根据选中或取消选中表单框来隐藏/显示内容 : Can this be done with css only?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9754137/