Enlarge the font size without changing the location of the input field

Imagine having an input field with a set height of 25px. If you decide to increase the font size within that text field, even though the dimensions remain constant, it may seem like extra padding has been added. Initially, at a normal font size, it appears like this:

BEFORE

https://i.stack.imgur.com/i5AP3.gif

Now, when the font size is increased, it gives the impression that additional padding has been inserted, similar to this:

AFTER

https://i.stack.imgur.com/wSb3f.gif

Despite checking the padding during debugging and attempting to apply box-sizing:border-box, the issue persists unchanged. Any assistance in resolving this matter would be greatly appreciated. Thank you.

You can easily replicate this scenario by adjusting the font-size.

<body>
  <div>
    <input type="text" value="HI"/>
    <input type="text" value="HELLO" style="font-size: 900px; height: 30px; width: 100%;"/>
    <input type="text" value="HI"/>
  </div>
</body>

Answer №1

To reset the vertical-align property, simply adjust it as needed.

The default value is baseline, with line-height being equal to font-size if left unchanged.

For a visual example using the vertical-align property:

input {
  vertical-align:middle;
  }

/* see div middle center. Note: the tallest input sets the line-height for that specific line */
div {
  background:linear-gradient(to top,rgba(0,0,0,0.2) 50%,rgba(0,0,0,0.1) 50%) ,linear-gradient(to left,rgba(0,0,0,0.2) 50%,rgba(0,0,0,0.1) 50%);
<div>
    <input type="text" value="HI"/> text
    <input type="text" value="HELLO" style="font-size: 90px; height: 30px; width:50px;"/> text
    <input type="text" value="HI"/>
  </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

The OK Button Dialogbox is currently malfunctioning

While using jQuery for a dialog box, I encountered an issue when trying to delete an element within it. After clicking the ok button, the dialog box did not redirect or close itself properly. The initial content in the dialog box seems to work fine. < ...

Angular Material Rotate Ink Bar to Vertical Orientation

After wanting to change the orientation of Angular Material's Tab Component to vertical, I visited this page (Tabs) and experimented with the CSS. By making the necessary adjustments, I successfully displayed the tabs vertically using the following CS ...

Utilizing CSS flex-end to position images

I am facing an issue with aligning the last item in my container named section-a. The height of the container is set to 100vh and it contains 3 items. I have tried using the property align-self:flex-end, but there are no visible changes. Can anyone help me ...

Adding items to a jCarousel using C# programming language is a simple process that involves following

I am struggling to display images in jcarousel using a C# Webmethod and jQuery Ajax. Here is my setup: My HTML structure: <div> <ul id="mycarousel" class="jcarousel-skin-tango" style="float: left"> </ul> </div ...

The navigation area is too small for the social media buttons to fit

Hi everyone, I'm encountering an issue with the social media buttons on my website. They're not staying in the navigation header area despite trying to use the float attribute. Here are some images illustrating the problem: https://i.stack.imgur ...

Having trouble bringing in SVG file into my React project

I am currently using React version 15.4.1 and I have tried implementing a solution from this link. However, instead of the component being rendered, I only see a string like this https://localhost:3001/dist/7553ed8d42edb0d73754cd9a5dea2168.svg This is how ...

Guide to choosing the directory for Visual Studio's compilation of LESS files

I currently use VS 2012 on my Windows 7. It seems that by default, it compiles LESS files to CSS in the same directory as the LESS file when I save. However, I would prefer to have all my CSS files saved in a "css" directory located next to the "less" dir ...

Ways to ensure that a div's height matches its width

Is there a way to make three divs, each with the CSS property display:inline-block, have a 1:1 ratio of width to height using only CSS? Currently, the width is set to 30% and the height to 75%, causing the width to be greater than the height. #our_servi ...

Conceal form after submission - Django 1.6

I'm currently working on a Django 1.6 project where I have this form: <form action="/proyecto/" method="POST" id="myform"> {% csrf_token %} <table> <span class="Separador_Modulo">& ...

Is there a way to prevent an external script from making changes to an inline style?

There is a mysterious script running on a page that seems to be controlling the height of an inline style. The source of this script modifying the height property is unknown. <div class="vgca-iframe-wrapper wpfa-initialized" style="heigh ...

Center an element over two other elements using CSS

I have three elements: checkout-left, checkout-right, and product-2 <div class="order-form"> <div class="checkout-left"> <div class="video another-video"> ...

What is the method for encoding and decoding a query string within an HTML object tag?

Within my code, I am utilizing an object tag that utilizes a data attribute to call a servlet. When passing a parameter to the URL, if the value is not in English but instead Arabic, for example, the value appears distorted when retrieved in the specified ...

Identifying geometric coordinates within Canvas

Currently, I am adding drag and drop functionality to my HTML5 Canvas application. I have encountered a challenge in determining how to detect if the shape being clicked on is not a rectangle or square. For instance, within my 'mousedown' event h ...

Errors that occur when parsing templates in Angular 2

I'm encountering a template parse error with my Angular 2 component using the following template: <div *ngIf="chapter == 1"> <p><h4><br><b>Exercise</b>: Get the Groceries starting point<br></h4 ...

How to Programmatically Disable OnClick Functionality in a Nested Div Using JavaScript and jQuery

I'm currently working on a Javascript application that allows users to enable/disable controls dynamically. While I've had success in disabling/enabling nested inputs and buttons, I'm facing an issue with disabling an onclick event within a ...

Guide to displaying names in PHP/HTML organized by group or rank

I am in the process of setting up a NASCAR league for my family members and I am currently developing a roster page where they can easily add or remove drivers. How can I display the drivers according to their rank as stored in the database? (A/B/C/D/E gro ...

Managing and Streaming Music in a Rails Application

Currently, I am storing mp3s using paperclip and they only play back if I utilize Amazon S3. However, I am hesitant to use Amazon S3 because I am unsure how to secure the files. Now, I am reconsidering my approach as I need to secure the mp3s and provide ...

How to Use Vue.js to Find the Nearest Div Element with a Specific

Below is the HTML code I am working with: <div id="app"> <div class="image"> <div class="overlay"> <p>Some overlay text</p> </div> <img src="https://placeimg.com/640/480/any" class="img-fluid"> ...

When the text input is selected, automatically scroll to the bottom

I found a codepen example by Chris Coyer and decided to fork it. My goal is to make the label move to the top instead of staying at the bottom, as in his original design. However, I am facing an issue with getting the cursor to move to the bottom when typ ...

Verify if a username is available using jQuery

When trying to register, I use this function to check the availability of a username. If the username already exists, the submit button is disabled. The check is done using a php script that queries the database for existing usernames. Everything works per ...