Floating label on focus

Developer
Size
2,261 Kb
Views
26,312

How do I make an floating label on focus?

This is a css only solution to http://codepen.io/Timurtek/pen/LblHd pen. Just for fun, not so good to use it... ;). What is a floating label on focus? How do you make a floating label on focus? This script and codes were developed by Pedro Campos on 13 October 2022, Thursday.

Floating label on focus Previews

Floating label on focus - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Floating label on focus</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="form"> <input type="text" name="email" id="email" required="required"> <label for="email">Email</label> <input type="password" name="password" id="password" required="required"> <label for="password">Password</label> <h1>Form Name</h1> <a href="#" class="forgot">Forgot Password?</a> <div class="bg"></div>
</div> <script src="js/index.js"></script>
</body>
</html>

Floating label on focus - Script Codes CSS Codes

body { height: 100%; min-height: 100%; margin: 0; background: url(http://www.timurtek.com/wp-content/uploads/2014/10/form-bg.jpg) no-repeat center center fixed; background-size: cover; font-family: arial;
}
html { height: 100%; }
.form { width: 264px; background-color: #ffffff; margin: 96px auto; padding: 96px 48px 48px 48px;
}
input[type="text"], input[type="password"] { position: relative; width: 240px; height: 44px; border: 1px solid #cccccc; padding: 0 12px; outline: none;
}
label { position: relative; top: -32px; left: 6px; padding: 0 6px; background-color: #ffffff; -webkit-transition: 0.2s linear; -moz-transition: 0.2s linear; transition: 0.2s linear;
}
input[type="text"]:focus + label, input[type="password"]:focus + label { top: -54px; }
input[type="text"]:valid + label, input[type="password"]:valid + label { top: -54px; }
/* background */
.bg { position: fixed; width: 100%; height: 100%; top: 0; left: 0; z-index: -1; background-color: rgba(0, 0, 0, 0.4); opacity: 0; -webkit-transition: 0.2s linear; -moz-transition: 0.2s linear; transition: 0.2s linear;
}
input[type="text"]:focus ~ .bg, input[type="password"]:focus ~ .bg { opacity: 1; }
/* h1 title */
h1 { margin: -190px 0 0 0; text-align: center; color: #cccccc; -webkit-transition: 0.2s linear; -moz-transition: 0.2s linear; transition: 0.2s linear;
}
input[type="text"]:focus ~ h1, input[type="password"]:focus ~ h1 { color: #58bff6; }
/* link */
.forgot { display: block; margin: 170px 0 0 0; color: #58bff6; outline: none;
}
.forgot:hover, .forgot:focus { color: #cccccc; }

Floating label on focus - Script Codes JS Codes

/* CSS only solution to https://codepen.io/Timurtek/pen/LblHd pen. */
Floating label on focus - Script Codes
Floating label on focus - Script Codes
Home Page Home
Developer Pedro Campos
Username pedrocampos
Uploaded October 13, 2022
Rating 3
Size 2,261 Kb
Views 26,312
Do you need developer help for Floating label on focus?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Pedro Campos (pedrocampos) Script Codes
Create amazing sales emails with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!