in Education by
I want to display the label of an input inside its input, so that when I click the input, the label will animate and go above the input and change the styles of the input's border. Like so: * { margin: 0; padding: 0; } form { width: 100%; max-width: 500px; margin: 0 auto; outline: 1px solid lightgrey; padding: 10px; } label, input[type='text'], input[type='password'] { font-size: 12pt; padding: 8px; } label { color: grey; } input { border: none; outline: none; border-bottom: 1px solid grey; }

Run code snippetExpand snippet How can I achieve this with CSS? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This looks a lot like the Google new material design inputs. I created custom inputs for you that look like what you are looking for. .input-group { position: relative; margin: 40px 0 20px; } input { font-size: 18px; padding: 10px 10px 10px 5px; display: block; width: 300px; border: none; border-bottom: 1px solid #757575; } input:focus { outline: none; } label { color: #999; font-size: 18px; font-weight: normal; position: absolute; pointer-events: none; left: 5px; top: 10px; transition: 0.2s ease all; -moz-transition: 0.2s ease all; -webkit-transition: 0.2s ease all; } input:focus ~ label, input:valid ~ label { top: -20px; font-size: 14px; color: #4285f4; } .bar { position: relative; display:block; width:315px; } .bar:before, .bar:after { content: ''; height: 2px; width: 0; bottom: 1px; position: absolute; background: #4285f4; transition: 0.2s ease all; -moz-transition: 0.2s ease all; -webkit-transition: 0.2s ease all; } .bar:before { left: 50%; } .bar:after { right: 50%; } input:focus ~ .bar:before, input:focus ~ .bar:after { width: 50%; } .highlight { position: absolute; height: 60%; width: 100px; top: 25%; left: 0; pointer-events: none; opacity: 0.5; } input:focus ~ .highlight { -webkit-animation: inputHighlighter 0.3s ease; -moz-animation: inputHighlighter 0.3s ease; animation: inputHighlighter 0.3s ease; } /* animations */ @-webkit-keyframes inputHighlighter { from { background: #4285f4; } to { width: 0; background: transparent; } } @-moz-keyframes inputHighlighter { from { background: #4285f4; } to { width: 0; background: transparent; } } @keyframes inputHighlighter { from { background: #4285f4; } to { width: 0; background: transparent; } }
Run code snippetExpand snippet

Related questions

0 votes
    I've successfully floated labels above form input fields when focused, but I'm stumped on how to keep ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
0 votes
    I have created floating label in input field.In chrome view is working fine, but not properly viewed in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Simulating transform-origin using translate (2 answers) Closed 3 years ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: Simulating transform-origin using translate (2 answers) Closed 3 years ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    As I tried to add a video on my top-wrapper previously. (Thank you so much for those who leave ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I have a Div element that pops up when clicking on a icon. This works fine on desktop. But when ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 3, 2022 in Education by JackTerrance
0 votes
    How can i wrap data in the table. Currently if template name is too long i get a scroll bar. I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    Why text inside / list is not affected (color of "item1", "item2" is not changed) by CSS applied ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    Still learning code. I am building a contact page and wanted to include my header bar at the top ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Still learning code. I am building a contact page and wanted to include my header bar at the top ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I've got the following html Title News 10. April 2011 First News 09. Feb. 2011 Second News With ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    Thanks for helping. I am trying to develop a static carousel (it won't move, but it acts like one) that stretches ... screen (but hidden, so no scrollbar). Here is the markup:...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    When assigning a background color of a table cell on hover, the box shadow is covered. I have found ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
...