To prevent the default alignment in case the text exceeds the input length, stop the automatic alignment

I have a query regarding an input field with a maximum length of 4 characters. The appearance is such that these 4 characters seem to be delineated by borders which are actually 3 lines displayed above the input field.

When I enter the fourth character, all the characters shift slightly to the left to accommodate the possibility of a fifth character being entered. However, when the input field loses focus, the characters align as expected.

Is there a way to address this issue using CSS, JavaScript, or jQuery? Or is this behavior dictated by the browser and cannot be altered?

.pin-field-wrapper {
  width: 175px;
  height: 72px;
  border-radius: 0px 13px 13px 0px;
  border-left: 1px solid #2A2A2A;
  font-size: 20px;
  display: inline-block;
  vertical-align: top;
  overflow: hidden;
  position: relative;
}

.pin-field {
  width: 100%;
  height: 100%;
  border-radius: 0px 13px 13px 0px;
  text-align: left;
  font-size: 44px;
  letter-spacing: 21px;
  padding-left: 8px;
  border: none;
  box-shadow: inset 0px 6px 6px -4px rgba(0, 0, 0, 0.96);
}

.pin-field-separator {
  position: absolute;
  height: 100%;
  width: 1px;
  background: #000;
  top: 0px;
  cursor: text;
}

.separator1 {
  left: 25%;
}

.separator2 {
  left: 50%;
}

.separator3 {
  left: 75%;
}
<div class="pin-field-wrapper">
  <input type="text" class="pin-field" placeholder="0000" maxlength="4">
  <div class="pin-field-separator separator1"></div>
  <div class="pin-field-separator separator2"></div>
  <div class="pin-field-separator separator3"></div>
</div>

Answer №1

Your font size should be adjusted to match the width of the input field. Consider making the field wider or reducing the font size.

.pin-field-wrapper {
  width: 200px;
  height: 72px;
  border-radius: 0px 13px 13px 0px;
  border-left: 1px solid #2A2A2A;
  font-size: 20px;
  display: inline-block;
  vertical-align: top;
  overflow: hidden;
  position: relative;
}

.pin-field {
  width: 100%;
  height: 100%;
  border-radius: 0px 13px 13px 0px;
  text-align: left;
  font-size: 44px;
  letter-spacing: 21px;
  padding-left: 8px;
  border: none;
  box-shadow: inset 0px 6px 6px -4px rgba(0, 0, 0, 0.96);
}

.pin-field-separator {
  position: absolute;
  height: 100%;
  width: 1px;
  background: #000;
  top: 0px;
  cursor: text;
}

.separator1 {
  left: 20%;
}

.separator2 {
  left: 44%;
}

.separator3 {
  left: 69%;
}
<div class="pin-field-wrapper">
  <input type="text" class="pin-field" placeholder="0000" maxlength="4">
  <div class="pin-field-separator separator1"></div>
  <div class="pin-field-separator separator2"></div>
  <div class="pin-field-separator separator3"></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

What is the process of transforming a jQuery load method into native JavaScript, without using any additional libraries?

Recently, I successfully implemented this ajax functionality using jQuery: $(function(){ $('#post-list a').click(function(e){ var url = $(this).attr('href'); $('#ajax-div').load(url+ " #post"); e.preventDefaul ...

What is the best way to display both an employee's name and ID on a single line using CSS and HTML?

I am currently working on an asp.net MVC app and facing an issue with adding employee ID and employee name on the same line, similar to the web design provided. I need to make modifications using HTML and CSS to achieve this. The problem is that I am unab ...

Managing PHP AJAX POST requests and storing data in a database

I have tested my PHP code by directly submitting a form without AJAX and it successfully writes the content into the database. However, when I try to do the same with AJAX, it doesn't work. Although the data appears to be transferred to my PHP file a ...

The CSS variables set within the :root section of styles.scss are not recognized as valid

Trying to implement global colors using CSS variables in my Angular 11 app. The styles.scss file contains: :root{ --primary : #0b68e8; --secondary:#ABCFFF; } .test-class{ background: var(--primary); } However, when applying this class in one ...

Transform various tables enclosed in separate div elements into sortable and filterable tables

I'm encountering an issue with making multiple tables sortable and searchable on one page. Despite all the tables having the same class and ID, only the first table is responsive to sorting and searching. I've followed a tutorial that recommends ...

Run a script tag prior to displaying the modal

Currently, I am attempting to display a bootstrap modal with dynamic content. One of the values being passed to the modal is the HTML that should appear inside it. The issue I am facing is that within the HTML content being passed, there is a script tag t ...

There seems to be an issue with updating the ng-model properly in angular-ui-tinymce

I have encountered a problem where I am attempting to add a DOM node when a custom button is clicked, but the model associated with the textarea is not being properly updated. To illustrate the issue, I have created a plunker as a demo. [https://plnkr.co ...

Consistent validation success with login authentication

I am currently working on a project that involves querying a server for user authentication using C# and ASP.NET, as I am still learning these technologies. Previously, I worked with JSP. The issue I am facing : For some reason, my methods are always re ...

Issue encountered: Cannot locate module: Error message - Unable to find 'stream' in 'C:devjszip-test ode_modulesjsziplib' folder

I am encountering an issue in my angular 7 application while using jszip v3.2.1. During the project build process (e.g., running npm start), I receive the following error message: ERROR in ./node_modules/jszip/lib/readable-stream-browser.js Module not fo ...

Where can I find the previous version of three.js? What is causing the incompatibility between the old and new versions of

Why is my app facing issues with the updated version of three.js? Can I find the previous version of three.js and why isn't the new version compatible? ...

Getting creative with jQuery: Adding a random class using addClass()

The html/css: <style> div.myWords p { display: hidden; } p.show { display: block; } </style> <div class="myWords"> <p>Hello</p> <p>Hola</p> <p>Bonjour</p> </div><!-- myWords --> Is ther ...

Managing session IDs in PHP after a successful login to dynamically update the menu bar option from "login" to "logout"

On my website, you will find a menubar with five menus: HOME, DATA, FEEDBACK, ABOUT, and LOGIN. I want to be able to log in by clicking on the login menu (a jQuery modal window pops up for logging in), and after successfully logging in, I would like the ...

The setInterval function continues to execute endlessly even after each interval is three months

I need to remove all expired OTP records every three months. In the file /sheduled-tasks/OTPRecords.js const prisma = require("../services/prisma"); const THREE_MONTHS = 1000 * 60 * 60 * 24 * 90; async function deleteExpiredOTPRecords() { ...

Using jquery to dynamically change audio source on click

Is there a way to dynamically change the audio src using jquery? <audio id="audio" controls="" > <source src="" type="audio/mpeg" /> </audio> <ul id="playlist"> <?php if($lists) { foreach ($lists as $list) { ?> ...

Javascript in Chrome can be used to initiate and conclude profiling

Is there a way to activate the CPU Profiler in the Chrome developer window using a Javascript call? For example: chrome.cpuprofiler.start(); //perform intensive operation chrome.cpuprofiler.stop(); Currently, my only option is to manually click on "s ...

The controller persists in its loop as it utilizes $state.go

As a newcomer to Angular, I am uncertain if this is the most effective solution. Within my state/route, there is a button that triggers the following function when clicked: _this.foo = function () { save(); $state.go("next"); } The issue arises w ...

I tried utilizing the useState hook to store the value, but surprisingly, it failed to update

I am brand new to Reactjs and currently working on creating an address form that includes 3 select options for country, state, and city. I have implemented React hooks in my project, where the page fetches a list of countries upon initial load. Subsequentl ...

Is it possible to eliminate the dedupe feature in npm?

By mistake, I accidentally ran the command npm dedupe and now all of my node_modules directories are flattened. While this reduces file size, it's making it more difficult to find things. Is there a way to reverse this and return to the hierarchical f ...

The phonegap page redirection is failing, as the 'location' property of the object does not function correctly

I'm attempting to implement a straightforward page redirection in PhoneGap using JavaScript. Within an iframe, I have the following code: window.parent.location("event_select.html"); Unfortunately, this approach is unsuccessful and results in the fo ...

How to emphasize a dataset in ChartJS stacked bar chart by hovering over the legend?

My Chart.js displays a horizontal stacked bar chart with legends corresponding to different classes. Here's a snippet (using dummy data, please ignore the random names): https://i.sstatic.net/XNTZZ.png The left labels represent users, while the legen ...