Created
March 21, 2025 02:22
-
-
Save MFathurrohmanMauludin/ccb9350eab1ed476cd84d84ffcff9a72 to your computer and use it in GitHub Desktop.
Pure CSS auto height chat input box
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div contenteditable class="magic-input" tab-index="1" data-placeholder="Write a message..." ></div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // These lines are just for add/remove placeholer native like | |
| function updateInput(element){ | |
| if(element.innerText && element.getAttribute('data-placeholder')){ | |
| element.setAttribute('data-placeholder-backup', element.getAttribute('data-placeholder')) | |
| element.removeAttribute('data-placeholder'); | |
| } | |
| if(!element.innerText && element.getAttribute('data-placeholder-backup')){ | |
| element.setAttribute('data-placeholder', element.getAttribute('data-placeholder-backup')) | |
| element.removeAttribute('data-placeholder-backup'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :root{ | |
| --max-input-height: 20vh; | |
| } | |
| .magic-input{ | |
| max-height: var(--max-input-height); | |
| overflow: hidden scroll; | |
| } | |
| // Make pen beauty | |
| body{ | |
| background-color: #18191d; | |
| color: #f5f5f5; | |
| } | |
| .magic-input{ | |
| position: fixed; | |
| bottom: 0; | |
| left: 0; | |
| width: 100%; | |
| outline: 0; | |
| background-color: #282e33; | |
| padding: 15px; | |
| line-height: 1.4em; | |
| &, &:before{ | |
| color: #818991; | |
| } | |
| &:before{ | |
| content: attr(data-placeholder); | |
| } | |
| &:focus{ | |
| color: #fff; | |
| &:before{ | |
| visibility: hidden; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment