Use the checked pseudo-class to implement the click button to switch the input box to the input state
See the effect first
Click the Edit on the right to activate the input on the left, and click the Finish on the right to save the input box content
pointer-events
We all know that the disabled attribute in <input disabled="true"/> can be used to make the input box uneditable, but as an element attribute, it needs to be modified using js. So how do we achieve this in a pure CSS environment?
The answer is to use the pointer-events attribute, which is used to define how an element responds to user clicks. For example, the following two examples:
<!-- This a tag sets pointer-events: auto --><astyle="pointer-events: auto;"href='https://blog.zhoujump.club'target="_blank">pointer-events: auto</a><!-- This a tag sets pointer-events: auto --><astyle="pointer-events: none;"href='https://blog.zhoujump.club'target="_blank">pointer-events: none</a>
In this example, the a tag with pointer-events: none cannot be clicked, while the a tag with pointer-events: auto can be clicked normally. We can use this method to achieve the effect of disabling the input box.
<divclass="s-box"><!-- I am an old tool user. If you don’t understand its usage, you can read the previous article --><inputid="s-edit"type="checkbox"/><inputclass="s-input"value="Click the 'Edit' button on the right →"/><!-- The content of this label is dynamically assigned using pseudo-elements, so leave it blank here --><labelclass="s-label"for="s-edit"></label></div><style>.s-box{//Externallargeboxstylebackground:#fff;border:1pxsolid#ddd;border-radius:12px;padding:10px;transition:all.3s;}.s-box:hover{//Externallargeboxstylewhentouchedbymousebox-shadow:0010px#ddd;transition:all.3s;}.s-input,.s-input:focus{//Designinputstyleandremoveitsdefaultstylewidth:calc(100%-60px);font-size:16px;padding:4px;outline:none;border:none;pointer-events:none;//Bydefault,wemakeituneditableborder:1pxsolid#fff;transition:all.3s;}.s-label{//Rightbuttonstylewidth:40px;cursor:pointer;float:right;text-align:center;}#s-edit:checked~.s-input{//Whenthebuttonisclicked,thecheckboxisselectedpointer-events:auto;//Maketheinputeditableborder:1pxsolid#ddd;border-radius:4px;transition:all.3s;}#s-edit{display:none;}//Hidetoolinput.s-label::after{content:"Edit";}//Assignbuttoncontentthroughpseudo-element#s-edit:checked~.s-label::after{content:"Complete";}//Assignbuttoncontentwhenthecheckboxisselectedbyclickingthebutton</style>