Styling CSS: Adjusting font sizes for placeholders and text boxes

I am struggling with styling an input field to have a font size of 45px while the placeholder text inside it should be 18px and vertically aligned in the middle. Unfortunately, my current code is not working in Chrome and Opera.

Can anyone offer a solution that does not involve JavaScript?

<input type="text" placeholder="Start typing your postal code..." />

   input {
        width: 300px;
        border: 2px solid red;
        padding: 0px 5px;
        line-height: 100px;
        font-size: 45px;
    }

    ::-webkit-input-placeholder {
        font-size: 18px;
        vertical-align: middle !important;
        line-height: 100px !important;
        color:#000;
        text-align:center;
    }
    ::-moz-placeholder {
        font-size: 18px;
        vertical-align: middle;
        line-height: 100px;
        color: #000;
        text-align: center;
    }
    :-ms-input-placeholder {
        font-size: 18px;
        vertical-align: middle;
        line-height: 100px;
        color: #000;
        text-align: center;
    }
    :-moz-placeholder {
        font-size: 18px;
        vertical-align: middle;
        line-height: 100px;
        color: #000;
        text-align: center;
    }

Answer №1

Consider including the input element before your pseudo-element to properly style your placeholder text. See example below:

input::-webkit-input-placeholder {
  font-size: 18px;
  vertical-align: middle;
  line-height: 100px;
  color: #000;
  text-align: center;
}

input::-moz-placeholder {
  font-size: 18px;
  vertical-align: middle;
  line-height: 100px;
  color: #000;
  text-align: center;
}

input:-ms-input-placeholder {
  font-size: 18px;
  vertical-align: middle;
  line-height: 100px;
  color: #000;
  text-align: center;
}

input::placeholder {
  font-size: 18px;
  vertical-align: middle;
  line-height: 100px;
  color: #000;
  text-align: center;
}

UPDATE

The options for styling placeholders may be limited. However, one workaround could involve using transform: translate(0, -50%);

input::placeholder {
  font-size: 18px;
  line-height: 100px;
  text-align: center;
  transform: translate(0, -50%);
}

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

Is it possible to send a message from a child iframe to its parent using HTML5 cross-browser compatibility

I've been following this tutorial on a video-sharing website, which demonstrates how to securely pass messages between an iframe and its parent. The tutorial can be found at a specific URL. To achieve this functionality, you would end up with a simila ...

JavaScript Switch Open/Close Mobile Navigation Menu

I'm currently facing a challenge with a specific issue. I want to implement a toggle menu for mobile devices on a website that I'm developing. It's functioning smoothly, and you can see it in action on this CodePen. The JavaScript code for ...

Ensuring the footer stays at the bottom of the page using Tailwindcss and ReactJS

I've read numerous articles and posts about achieving this, but none of the methods seem to be effective for me. My goal is to have the footer stick to the bottom of the page when viewed on mobile devices. It displays correctly on larger screens, but ...

Using jQuery and HTML to create numerous links that direct to a solitary iframe

I created a basic overlay setup using css, html, and jQuery. Here's how it looks: <a class="activator" id="activator" style="" href="#">hello</a> <div class="overlay" id="overlay" style="display:none;"></div> <div style="d ...

The include_once function is functioning correctly on one page, but encountering issues on another page. No errors are being displayed

I am currently using Bootstrap for my website. When I include the bottom and footer sections in actualites.php (at the end of the file), everything works smoothly. As I construct my website, I am trying to incorporate content via URL. My code looks like t ...

When adjusting window size, the input shifts towards the left

Is there a way to prevent my input and login button from moving to the left when resizing the window? I am new to HTML and CSS and would appreciate any tips on keeping them in place. Below is my CSS code: #absolute { position: absolute; top: 411px; le ...

Adding an arrow to a Material UI popover similar to a Tooltip

Can an Arrow be added to the Popover similar to the one in the ToolTip? https://i.stack.imgur.com/syWfg.png https://i.stack.imgur.com/4vBpC.png Is it possible to include an Arrow in the design of the Popover? ...

"The application is experiencing issues with loading styles correctly when using jQuery append (Fiddler has been

When attempting to load a div tag using the .append() method, the styles are not loading correctly. Here's the code that was tested: <section id="year-2020" class="tab-panel"> <div class="row accordion"> <header> ...

Tips for utilizing @htmlattributes when configuring a datepicker:

Hello, I am attempting to change a simple input field into a date form. I have tried using the DateTime property with @Html.TextBoxFor(model => model.dateFin, new { type = "date" }) but it was not successful. As a result, I am resorting to using a simpl ...

Steps for positioning a div with list items to match the height of its parent container

I've been grappling with this problem for a long time now. Within the parent div "wrapper," there is a child div called "sidebar-wrapper" that contains an ul with li elements. I'm trying to make the height of "sidebar-wrapper" adjust to match t ...

What is the best way to create a "tile-based board" for this game?

I am working on a project to create a board made up of tiles, but I am facing difficulty in filling up the entire board area. Currently, I have only managed to create 1 column of the board, as shown in the image. Can someone guide me on how to fill the ent ...

Ways to add gaps between flexbox items within a single row?

I have a coding dilemma where I am trying to display two items in the same row with a 12px gap between them, but my current method is not working as desired. I want there to be space between the A's and B's without resorting to traditional techni ...

What is the reason behind Material UI's decision to utilize display flex instead of display grid?

The Grid component implements the grid system. It leverages the Flexbox module in CSS to provide great flexibility. What is the reason behind material UI using display flex instead of display grid? ...

Cycle through items and switch states using classList in JavaScript

Rules: Your task is to utilize javascript and the classList property to switch the elements with the .highlight class. You need to loop through all the <li> elements and change the class of .highlight on each one. Do not make any changes to the HTML ...

How can I create a single-page application that adjusts to different screen sizes effortlessly?

I am working on developing a single-page application that fits within one screen with the following structure: There is a fixed header that includes: Two columns (1/3 for left, 2/3 for right) : a logo on the left a breadcrumb on the right. The ...

Is the CSS Transition Solely Active for the Introductory Animation?

I'm currently looking to enhance the smoothness of div expansion and contraction on hover using CSS transitions. However, I have noticed that the Transition property only seems to affect the entry animation (i.e., when the mouse hovers and the div exp ...

Arrange CSS to distribute list items across two rows with an unlimited number of items

I need my list items to be arranged in 2 rows like the following: item 1 item 3 item 5 item 7 item 9 .... item 2 item 4 item 6 item 8 ...... My CSS skills are not great, so I am struggling to find a solution for this. I have at ...

Ways to update the title of a Magento widget

I've added a widget to showcase new products on my Home page and it's displaying perfectly. However, I want to get rid of the title "New Product" that comes with it. This pesky little thing needs to go! https://i.sstatic.net/P0NeS.jpg I'm ...

Is there a way to activate a click event on a particular child element within a parent element?

When attempting to click on a specific descendant of an element, I located the ancestor using ng-class since it lacked an id. yes = document.querySelectorAll('[ng-controller = "inventoryController"]') Having found the desired ancestor, ...

Issue with Google Chart overlapping drop down menu in CSS紿orizontal scrollingyan

I've exhausted all my options. I've experimented with positioning and z-indexes, but no matter what I try, the drop-down menu remains hidden behind the google chart. It functions properly on Firefox, but not on Chrome or IE. Any helpful advice wo ...