Ways to ensure the input placeholder remains visible as the user is typing

I'm facing a fresh and fascinating challenge. Rather than the typical behavior of the placeholder text vanishing as soon as the user begins typing, I'd like it to stay in place but move over to the right side of the input box.

Can this be accomplished using just standard HTML placeholders? Any suggestions on how I can make this happen?

Appreciate any help. Thanks

Answer №1

Standard HTML placeholders automatically disappear, but you can create a workaround by using CSS to move an element that poses as the placeholder when the user starts typing (:placeholder-shown).

One way to achieve this is:

.wrapper {
  position: relative;
  font-family: sans-serif;
  font-size: 14px;
  width: max-content;
}

.placeholder {
  position: absolute;
  right: 4px;
  top: 2px;
  pointer-events: none;
  opacity: .5;
}

.input:placeholder-shown + .placeholder {
  /* hide fake placeholder if real placeholder is shown */
  opacity: 0;
}
<div class="wrapper">
  <input type="text" class="input" placeholder="Test">
  <div class="placeholder">Test</div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Preventing React setState from replacing the entire object

When attempting to update a customer's age using setState, the object is altered before calling setState, but the existing object is not updated. customerOnChange(event, field) { //Customer's age currently set at 80 var customer = { ...t ...

Glowing effects on svg shapes

I'm looking to add a pulsing light animation around an SVG half circle shape that I have created. After experimenting with CSS and Webkit, the closest I've come is achieving a pulsing light around the parent element, rather than the actual shape ...

Invoke the function defined within a modal when dismissing a ui-bootstrap modal

Inside my ui-bootstrap modal controller, I have a $watch function set up for a variable. The code snippet looks like this: main.controller('modalCtrl', ['$scope', '$rootScope', '$modalInstance', function ($sc ...

Switching item in dropdown menu with JavaScript

How can I use JavaScript to change the selected item in a drop-down menu? <select name="example_length" aria-controls="example" class=""> <option value="10">10</option> <option value="25">25</option> <option value="50"> ...

Using JavaScript to interact with elements inside an iframe on a webpage

In a simple scenario, I am experiencing incorrect results. Code snippet from MyFrame.HTML: <!DOCTYPE html> <html> <head> <title>My Frame</title> </head> <body> <a href="https://www.google.com& ...

While developing an exam portal with Angular and Spring Boot, I encountered an issue when trying to incorporate a name field as [name]

Component.html <div class="bootstrap-wrapper" *ngIf="!isSubmit"> <div class="container-fluid"> <div class="row"> <div class="col-md-2"> <!- ...

Leveraging the XMLHTTP object to extract data from websites with VBA

I am currently working on extracting the "key people" information from a Wikipedia page: https://en.wikipedia.org/wiki/Abbott_Laboratories and inserting that data into my Excel spreadsheet. I have successfully achieved this using xml http, which I find ef ...

Trigger the execution of the second function upon the successful completion of the first

In the following code, my concept is to display: The clicked kingdom (clicked_id) initiates an attack on (clicked_id). https://i.stack.imgur.com/Bx8QW.png https://i.stack.imgur.com/Cg2GL.png https://i.stack.imgur.com/gUNxM.png How can I trigger the sec ...

What is the best way to generate a cookie in svelte and retrieve it later on?

I have been working on implementing a cookie in Svelte (while also using Svelte Kit) for the purpose of storing a JWT Token used in authentication processes. I initially tried using pure JavaScript code like getCookie() and setCookie(), following the gui ...

Best practices for structuring npm scripts and multiple webpack configurations

My project consists of multiple dashboards, and I've decided to create separate scripts in my package.json for each one. Building all the dashboards during development when you only need to work on one can be time-consuming. So, I discovered that it&a ...

Choosing specific information in Typescript response

I am encountering an issue with my HTML where it displays undefined(undefined). I have checked the data in the debugger and I suspect that there may be an error in how I am using the select data. Here is a snippet of the code: <div *ngIf="publishIt ...

Is there a way to use AngularJS foreach to extract targeted values by a specified key from a JSON object?

I have received a JSON object from an elastic search query as shown below: How can I extract the Agent and calls values from this JSON data? $scope.results = client .query(oQuery.query($scope.queryTerm || '*')) . ...

Experimenting with file uploads in AngularJS with the help of Protractor

For file uploads in our application, we are utilizing ngFlow. With protractor being used for testing, we have several test case scenarios to validate such as unsupported file formats and maximum file size limitations. How can we effectively select files ...

What is causing my conditional operator to malfunction?

What is the reason for the output being undefined instead of "old" in this scenario? function test(age) { return 12 < age ? "old" : "young"; } test(15); ...

Can you display names in capital letters from the randomUser.me API?

Apologies if this is not the appropriate platform for my query. Just to provide context, I am a designer with minimal experience in APIs and Javascript. I am currently utilizing the randomUser API to create a JSON file or URL that can be integrated into I ...

Assistance needed in Android Studio for incorporating a button using a Style Sheet (CSS)

Hey there! I'm just starting out with Android programming and could use some guidance. Can someone assist me in creating three simple buttons for my app? The buttons should be colored green, blue, and red, with a thin glowing outline around them. If ...

Collapsing or expanding the Material UI accordion may lead to flickering on the page

import React from "react"; import { makeStyles } from "@material-ui/core/styles"; import Accordion from "@material-ui/core/Accordion"; import AccordionDetails from "@material-ui/core/AccordionDetails"; import Accordi ...

What is the best way to position href text on the top of a rectangular div box?

Whenever I try to position the text above the rectangle, it disables the link. How can I resolve this issue? Additionally, when attempting to change the color of the "San Diego" text, I'm unable to adjust its position. Just a heads up, I am new to HT ...

When utilizing the React onclick function, it generates an increase in state values rather than modifying

I'm currently working on a function that changes the state property, "changedMarkup", when a button is clicked. Initialization constructor() { super(); this.state = { value: 0, changedMarkup: 0 }; } Render Function render() ...

Execute the javascript code when the radio button is selected

For my Rails app, I want a straightforward feature where a JavaScript function runs only if a radio button has been selected. The user should be presented with multiple radio buttons without any default selection. Upon clicking a "Run" button, the followin ...