Hello guys today we will learn how to make a locked unlocked input field using HTML & CSS
First we need to create two files index.html and Style.css then we need to do code for it.
Step:1
Add below code inside index.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Lock Unlock Input Field Using Css Only</title> <link rel="stylesheet" type="text/css" href="style.css"> <link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@500&display=swap" rel="stylesheet"> </head> <body> <div class="field_outer"> <input class="icon_check" type="checkbox" /> <span class="icon"></span> <input type="text" placeholder="'Unlock' me by clicking the lock icon" /> </div> </body> </html>
Step:2
Then we need to add code for style.css which code i provide in below screen.
*{ outline: none; padding: 0; margin: 0; font-family: 'IBM Plex Sans', sans-serif; } html, body { height: 100vh; } body { display: flex; align-items: center; background: #cae3e7; color: #4a5568; height: 100%; font-size: 16px; margin: 0; padding: 0; } div { --field-size: 50px; --field-border-color: #ccc; margin: 0 auto; font-size: 1rem; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); background: #ffffff; border-radius: 5px; position: relative; width: 400px; overflow: hidden; display: -webkit-box; display: flex; background: white; } div input[type="checkbox"] { position: absolute; opacity: 0; width: var(--field-size); height: var(--field-size); cursor: pointer; padding: 0; margin: 0; } div input[type="checkbox"]:hover + span { background-image: url("unlock.png"); background-repeat: no-repeat; background-position: center center; background-size: 50%; } div input[type="checkbox"]:checked + span { background-image: url("unlock.png"); background-repeat: no-repeat; background-position: center center; background-size: 50%; } div input[type="checkbox"]:checked + span::before, div input[type="checkbox"]:checked + span::after { pointer-events: none; } div input[type="checkbox"]:checked + span::after { -webkit-transform: translateY(-100%); transform: translateY(-100%); } div input[type="checkbox"]:checked + span::before { -webkit-transform: translateY(100%); transform: translateY(100%); } div input[type="checkbox"] + span { width: var(--field-size); height: var(--field-size); border-right: 1px solid var(--field-border-color); background-image: url("lock.png"); background-repeat: no-repeat; background-position: center center; background-size: 50%; cursor: pointer; } div input[type="checkbox"] + span::after, div input[type="checkbox"] + span::before { content: ""; position: absolute; right: 0; height: 50%; left: var(--field-size); -webkit-transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1); transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1); background: rgba(0, 0, 0, 0.075); z-index: 2; cursor: not-allowed; } div input[type="checkbox"] + span::after { top: 0; } div input[type="checkbox"] + span::before { bottom: 0; } div input[type="text"] { padding: 1em; border: 0; -webkit-box-flex: 1; flex: 1; font-size: 1rem; --placeholder-color: #ababab; font-family: inherit; } div input[type="text"]::-webkit-input-placeholder { color: var(--placeholder-color); } div input[type="text"]:-ms-input-placeholder { color: var(--placeholder-color); } div input[type="text"]::-moz-placeholder { color: var(--placeholder-color); } div input[type="text"]:-moz-placeholder { color: var(--placeholder-color); }
how can unlock field website in html?