Using a checkbox to control subsequent elements
The checkbox control can toggle its state depending on the mouse's click, and can be used in CSS to set the style for a checkbox in the selected state, using the checked pseudo class. In conjunction with the "+" or "~" selector in CSS, you can control the element after it from the checkbox operation. Even with label labels, you can achieve more results.
Run
CSS Code copy content to clipboard
- <! DOCTYPE html>
- <style>
- [type=checkbox]+* {display:none;}
- [type=checkbox]:checked+* {display:inline-block;}
- </style>
- <input type="checkbox" /><input/>
In this example, the text box is hidden by default, and the text box is displayed only when the checkbox is checked. This allows you to achieve no JavaScript switching effect.
Someone might think it's too much of an eyesore to put a checkbox on the page. In fact, even if the checkbox itself is hidden, CSS: Checked's judgment is still in force. So we can hide this checkbox and let the label label set the response area for it.
Run
CSS Code copy content to clipboard
- <! DOCTYPE html>
- <style>
- Body {font:14px/1.5 Microsoft James Black;}
- [Type=checkbox] {display:none;}
- [Type=checkbox]~input {display:none;}
- [Type=checkbox]:checked~input {display:inline-block;}
- [Type=checkbox]~span {cursor:pointer; Margin-right:10px;}
- [Type=checkbox]~span:before {content:' dot I show text box ';}
- [Type=checkbox]~span:hover {color:#C30;}
- [Type=checkbox]:checked~span:before {content:' dot I hide text box ';}
- </style>
- <label><input type="checkbox" /><span></span><input/></label>
However, this approach is somewhat limited, because the current CSS does not support: has,:p arent, and so on, so the supported operations are limited to the label, and the default behavior of the label will always affect its internal first control, the above code even if the text box pop-up, It is also possible to trigger the default action of the label when clicking on the text box, causing the text box to be hidden.
All in all, here's just the way to do it, and it's up to everyone to study how to use it.