What steps can I take to address the issue of inconsistent vertical alignment of placeholder text on both desktop and mobile

The alignment of my input placeholder text varies across different browsers and devices. While it appears correctly in Firefox and Chrome desktop, Safari desktop and mobile, as well as Firefox Mobile and Chrome Mobile display the text too high.

I've attempted to adjust padding and line-height settings without success in resolving the issue.

For reference, here is the code snippet exhibiting the problem on mobile devices:

https://codepen.io/paulspelman/pen/XGvVrE

* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

body {
  padding: 0;
  margin: 0;
  color: #00bb80;
  background: #101010;
}

.wrapper {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
  margin: 0 auto;
  max-width: 900px;
  font-family: sans-serif;
  text-align: center;
  width: 70%;
}

.input-holder {
  position: relative;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  height: 4rem;
  margin: 0 auto 2rem auto;
}

<input {
  height: 4rem;
  width: 12rem;
  font-size: 2rem;
  font-weight: 300;
  text-align: left;
  padding: 0 0 0.2rem 1rem;
  margin-left: 0.5rem;
  color: #9b9b9b;
  background: #101010;
  border: 1px solid #434343;
  border-right: 0;
  border-radius: 0;
}

input::-webkit-input-placeholder {
  font-size: 1.1rem;
  font-weight: 400;
  position: relative;
  top: -0.3rem;
  color: #9b9b9b;
}

... (remaining CSS code) ...

</div></pre>
<pre><code><div class="wrapper"> 

    <div class="input-holder">
        <p class="dollar-sign">$</p>
        <input type="text" class="user-input" placeholder=" Placeholder text" maxlength="4" value="" autocomplete="off">
        <button class="calculate-button">&rarr;</button>
    </div>

</div>

Answer №1

There's a clever workaround that can solve this issue. You just have to define:

@supports(font-synthesis: inherit) { // not supported by Chrome but works on Safari
   input::placeholder {
     line-height:3em
  }
}

Check out the Demo here

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 best way to populate a textarea element in Jade with text without any whitespace?

My current solution is functioning perfectly: textarea. #{myObject.myVar} Despite the success, Jade throws a warning when compiling the file: Cannot read property 'myVar' of undefined This warning makes sense since myObject may not be p ...

JavaScript/jquery loop with an increasing index each iteration

I am currently working with a JSON file that contains paths to various images. I want to regularly add more image paths to this file and display them on an HTML page. However, I am encountering an issue when using the $.each method - the index remains the ...

Entry Points for Logging In

After stumbling upon this pre-styled Material UI login page example, I decided that it was exactly what I needed. However, I ran into an issue when trying to figure out how to store the username and password values. Whenever I try to use 'State' ...

Does reducing the number of HTML, PHP, or CSS files truly have a significant impact on improving a webpage's performance, or is it just a minor factor?

Discovering a new HTML minifier on Ajaxian got me thinking - is minimizing HTML, PHP, or CSS files truly a significant improvement for webpages? Would shrinking files that are 100 lines long on average make a noticeable impact? ...

Set the navigation height to fill the entire screen

When the article section expands downwards, the left navigation bar does not extend all the way down. I want the navigation with the background color to expand downwards together with the article text on the right. I attempted to use "height: 100%;" for t ...

"Enhanced visuals with parallax scrolling feature implemented on various sections for an engaging

With 4 sections, each featuring a background image and text in the middle, I encountered an issue when attempting to have them fixed while scrolling. The goal was for the section below the first one to overlap the one above it along with its text as we scr ...

Error: controller undefined

As I delve into a Coursera course on AngularJS, I've encountered a perplexing issue with a controller. The console is indicating that it is not defined. Upon running it through the https://validator.w3.org/, a recurring error message mentioning that ...

The stylesheet malfunctioned while attempting to load varying layouts in separate controllers

Hey, I encountered a strange issue. After clicking on the three pages displayed in the images below: Step 1 controller welcome Step 2 other controllers Step 3, back to step 1 view controller welcome The final image, when returning to controller welcom ...

Styling with CSS using only numerical values

My website features a section that states "Weekdays 10:00 ~ 18:00 /*linebreak/ Saturdays 10:00 ~ 13:30" I am looking to format only the numerical values in the font "Courier New," specifically the "10:00 ~ 18:00" and "10:00 ~ 13:30" sections. The remainin ...

Java script request via Ajax is failing to execute

Within my HTML code, I have included a button like so: <button type="submit" id="post-form" class="btn btn-primary" onclick="send()">Send</button> Accompanying this is the JavaScript function send() : fu ...

Using AngularJS to retrieve DOM elements within a directive's controller

Currently, I am in the process of creating a custom image carousel directive using only AngularJS and no additional libraries. simpleCarousel.$inject = []; function simpleCarousel() { var directive = { restrict: 'E', templat ...

"Create a flexible CSS grid with a dynamically changing number of rows and customizble

I am currently working on a project that involves creating a dynamic grid layout with two resizable columns, namely #red-container and #green-container. The goal is to make each column resizable horizontally while also allowing the main container #containe ...

Guide on inserting text input value into the href attribute of a hyperlink

Lately, I've been facing an issue that has been troubling me for the past few hours. I have a search input field where users can enter text and click send. The entered text should then be added to the href attribute and sent to the results page for qu ...

Experiencing problems with various React Carousel libraries when it comes to displaying

I have been attempting to integrate Carousel libraries into my react app, but I am encountering a common issue with all of them. The Carousels show the items on the first slide, but subsequent slides do not display any items, even though they exist within ...

Position the button to the right using the Bootstrap float-right class

Currently, I am utilizing reactstrap within my React component. My primary intention is to position a button to the right side of the container but unfortunately, the following code doesn't achieve the desired result: <td class="col-md-4 clearfix" ...

Watching mov and mp4 files directly in your web browser

I am currently experimenting with the HTML5 video tag and database video files. In my database, I have several records that contain both mov and mp4 files. While HTML5 video tag supports mp4 files, it's a different story when it comes to mov files. I& ...

Utilizing consistent CSS styles across VueJS components

Currently tackling a VueJS 2 project and facing issues with scoped styling when cleaning up the code. My setup involves 3 components that share similarities, prompting me to utilize mixins for consolidating the code into one file. Each component makes use ...

Press the button to move the slider

I implemented a scroll slider with dynamic content by following an example from jquery.com. Now, I am looking to enhance it further by adding left and right image buttons to control the scrolling and remove the scrollbar completely. <html lang="en"&g ...

The sticky navigation bar hack (implementing fixed positioning with jQuery)

Essentially, when the navigation bar (or any other element) reaches the top of the page or window, a class called "sticky" is added to the element and CSS styles it as fixed. This functionality acts like an IF statement - if the element is far from the top ...

Firefoxi is the only browser that exhibits strange padding and margin behavior

Check out this webpage at: www.bit.ly/1b4dUqs Most browsers display the page correctly, but there seems to be an issue with Firefox's (latest version) handling of margin-top/padding-top styles. If anyone has a solution for this problem, please share ...