Label Pattern with just CSS

Developer
Size
3,617 Kb
Views
50,600

How do I make an label pattern with just css?

The <label> is the placeholder. It shows because the input is on top of it with a transparent background. On focus we can move it, with just CSS, through an adacent sibling combinator and :focus. If the input is :valid, it can have a solid background, thus hiding the "placeholder".. What is a label pattern with just css? How do you make a label pattern with just css? This script and codes were developed by Chris Coyier on 04 July 2022, Monday.

Label Pattern with just CSS Previews

Label Pattern with just CSS - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Label Pattern with just CSS</title> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ * { box-sizing: border-box;
}
html { font: 14px/1.4 Sans-Serif;
}
form { width: 320px; float: left; margin: 20px;
}
form > div { position: relative; overflow: hidden;
}
form input, form textarea { width: 100%; border: 2px solid gray; background: none; position: relative; top: 0; left: 0; z-index: 1; padding: 8px 12px; outline: 0;
}
form input:valid, form textarea:valid { background: white;
}
form input:focus, form textarea:focus { border-color: #f06d06;
}
form input:focus + label, form textarea:focus + label { background: #f06d06; color: white; font-size: 70%; padding: 1px 6px; z-index: 2; text-transform: uppercase;
}
form label { transition: background 0.2s, color 0.2s, top 0.2s, bottom 0.2s, right 0.2s, left 0.2s; position: absolute; color: #999; padding: 7px 6px;
}
form textarea { display: block; resize: vertical;
}
form.go-bottom input, form.go-bottom textarea { padding: 12px 12px 12px 12px;
}
form.go-bottom label { top: 0; bottom: 0; left: 0; width: 100%;
}
form.go-bottom input:focus, form.go-bottom textarea:focus { padding: 4px 6px 20px 6px;
}
form.go-bottom input:focus + label, form.go-bottom textarea:focus + label { top: 100%; margin-top: -16px;
}
form.go-right label { top: 2px; right: 100%; width: 100%; margin-right: -100%; bottom: 2px;
}
form.go-right input:focus + label, form.go-right textarea:focus + label { right: 0; margin-right: 0; width: 40%; padding-top: 5px;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <form class="go-bottom"> <h2>To Bottom</h2> <div> <input id="name" name="name" type="text" required> <label for="name">Your Name</label> </div> <div> <input id="phone" name="phone" type="tel" required> <label for="phone">Primary Phone</label> </div> <div> <textarea id="message" name="phone" required></textarea> <label for="message">Message</label> </div>
</form>
<form class="go-right"> <h2>To Right</h2> <div> <input id="name" name="name" type="text" required> <label for="name">Your Name</label> </div> <div> <input id="phone" name="phone" type="tel" required> <label for="phone">Primary Phone</label> </div> <div> <textarea id="message" name="phone" required></textarea> <label for="message">Message</label> </div>
</form> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
</body>
</html>

Label Pattern with just CSS - Script Codes CSS Codes

* { box-sizing: border-box;
}
html { font: 14px/1.4 Sans-Serif;
}
form { width: 320px; float: left; margin: 20px;
}
form > div { position: relative; overflow: hidden;
}
form input, form textarea { width: 100%; border: 2px solid gray; background: none; position: relative; top: 0; left: 0; z-index: 1; padding: 8px 12px; outline: 0;
}
form input:valid, form textarea:valid { background: white;
}
form input:focus, form textarea:focus { border-color: #f06d06;
}
form input:focus + label, form textarea:focus + label { background: #f06d06; color: white; font-size: 70%; padding: 1px 6px; z-index: 2; text-transform: uppercase;
}
form label { transition: background 0.2s, color 0.2s, top 0.2s, bottom 0.2s, right 0.2s, left 0.2s; position: absolute; color: #999; padding: 7px 6px;
}
form textarea { display: block; resize: vertical;
}
form.go-bottom input, form.go-bottom textarea { padding: 12px 12px 12px 12px;
}
form.go-bottom label { top: 0; bottom: 0; left: 0; width: 100%;
}
form.go-bottom input:focus, form.go-bottom textarea:focus { padding: 4px 6px 20px 6px;
}
form.go-bottom input:focus + label, form.go-bottom textarea:focus + label { top: 100%; margin-top: -16px;
}
form.go-right label { top: 2px; right: 100%; width: 100%; margin-right: -100%; bottom: 2px;
}
form.go-right input:focus + label, form.go-right textarea:focus + label { right: 0; margin-right: 0; width: 40%; padding-top: 5px;
}
Label Pattern with just CSS - Script Codes
Label Pattern with just CSS - Script Codes
Home Page Home
Developer Chris Coyier
Username chriscoyier
Uploaded July 04, 2022
Rating 4.5
Size 3,617 Kb
Views 50,600
Do you need developer help for Label Pattern with just CSS?

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!

Chris Coyier (chriscoyier) Script Codes
Create amazing art & images 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!