Eliminate any unnecessary or hidden spacing on the left side of the options within an HTML select

Currently, I am in the process of creating a Registration Form and encountering a challenge with aligning the input[type="text"] placeholder and the "pseudo" placeholder for a <select> element. My goal is to have both placeholders left-aligned flush with each other.

I referred to the placeholder for a select HTML element as "pseudo" because there isn't a default placeholder option for a select element. Instead, the first option within the select is displayed in place of a placeholder.

In the provided screenshot, you can observe two select elements - one displaying "Country" as the first option text, and another showing "HOW SOON DO YOU WANT YOUR BOOK?" as the initial option text. Both these select elements seem to have an indentation compared to the input[type="text"] placeholder text, making it challenging to align them precisely.

https://i.sstatic.net/CDUNx.png

input[type="text"].couture-input-underline,
input[type="password"].couture-input-underline,
input[type="number"].couture-input-underline,
select.couture-input-underline
{
  width: 300px;
  display: block;
  font-size: 22px;
  border: 0px solid #7f7f7f;
  border-bottom-width: 1px;
  background: transparent;
  outline: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  -webkit-border-radius: 0;
  -moz-border-radius: 0;
  -o-border-radius: 0;
  -ms-border-radius: 0;
  border-radius: 0;
  padding: 0;
  margin:0;
  margin-bottom: 10px;
}

.text-match-placeholder{
  color: #ACACAC;
}

select option
{
  outline: none;
  -webkit-appearance: none;
  padding: 0;
  margin: 0;
}
<select class="couture-input-underline text-match-placeholder">
  <option value>Choose</option>
  <option>First</option>
  <option>Second</option>
 </select>
<input type="text" class="couture-input-underline" placeholder="Text Box One" />

Answer №1

In my exploration, I have identified an issue that only occurs in Firefox. Upon investigation, I discovered that the problem lies within the following declaration:

 select > option {
 -moz-padding-start: 3px;
 }

This declaration is part of the user agent styles. You can learn more about inspecting user agent styles in Firefox here.

Interestingly, attempting to override this declaration for select > option in your CSS does not produce the desired result.

 /** Adding the following
     to your CSS will not resolve 
     the issue
 **/

 select > option {
 -moz-padding-start: 0 !important;
 }

My theory is that there may be a "ghost" element mimicking the <option> element, which explains why your CSS rules are not affecting it.

To address this issue, a somewhat unconventional fix is required:

input[type="text"].couture-input-underline,
input[type="password"].couture-input-underline,
input[type="number"].couture-input-underline,
select.couture-input-underline
{
  padding-left: 3px;
}
select.couture-input-underline {

  -moz-padding-start: 0px;
}

You can view the implementation here.

This workaround essentially adds a left padding of 3px to every input field. In Firefox, this causes the option to be indented by 6px, so we specifically reset it for the select element.

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 there a way to clear out all items from the cart using PHP?

I have a shopping cart with items that I want to remove all at once. I tried creating a submit button with the post method called 'remove_all', but it's not working and showing an error message saying "The requested URL was not found on this ...

The radio input is not being properly checked using ng-checked in Angular

The ng-checked attribute is causing issues in the application, specifically with radio buttons. It seems to be working fine for checkboxes but not for radio buttons. <input type="radio" class="radio" name="job_class_radio" ng-checked="key===jobClassDat ...

Tips for adjusting the font size on the Google Maps mapType controller

Is it possible to adjust the font size of a Google Maps mapType controller using HTML or CSS? I've managed to change the size of the controller, but struggling with the font size. HTML: <div #map id="map" style="height:250px;"></div> C ...

What is the best way to connect a Jquery plugin to a table within a partial view following an ajax request?

I have a main view that utilizes a partial view to display items in a table format. Main View (Enclosed within a div, it references the Partial View) <div id="divList"> @Html.Action("_list") </div> Partial View (Displaying a list of it ...

How to replicate a WordPress menu bar

Embarking on my coding journey, I've completed courses in HTML, PHP, CSS, JavaScript, and MySQL. Now, I've decided to dive into hands-on learning by creating a Wordpress child theme. My current challenge is figuring out how to overlay two differ ...

Conceal the prominent image when viewing a single post

I've been attempting to hide the featured image on single post view but so far, neither a plugin nor the theme panel option has worked for me. I even tried adding custom CSS code without success. Is there another method that can be used to hide the fe ...

Discover the second character in the sequence and substitute it with a different numeral

I need to manipulate a string where I want to replace the second digit with a random number. The challenge lies in identifying the second digit and performing the replacement. How can I accomplish this task? 1. "data[KPI][0][rows][0][name]" 2. "data[KPI][ ...

What's causing the zero to appear after the ajax call?

This is my first time learning Ajax with WordPress and I'm trying to implement Ajax functionality with a widget. However, I am encountering an issue where I get a 0 after the form is submitted. Can someone provide guidance and explain why this is hap ...

Ensuring the input field and button are positioned in a horizontal line

Currently, I am developing a to-do list application using React and Chakra UI. I am trying to align the input field and the button on the same line for a more organized layout. This is the current layout: image I aim to achieve a design similar to this: ...

Tips for breaking up array elements across multiple "tr" tags

In this particular example, I have a Fiddle set up with multiple tr elements displayed within an ng-repeat. My goal is to have three td elements per row. Would it be necessary to use an inner angularjs ng-repeat and split the iconDets array for this purpos ...

Automating the process of disabling a function on Internet Explorer

As I work on a new Internet Explorer plug-in, I've come across a frustrating feature that has been present since at least IE7. This feature allows users to modify the sizing of HTML elements in editable windows, like rich text emails in GMail, by simp ...

Using jQuery, generate a dynamic form to create a multidimensional array

I've set up a form where additional dropdowns can be dynamically added if the user clicks on a specific link. Here's an example of how it looks: <div class="dynamic-sale"> <select name="sizes[]" id="sizes" class="entry-dropdown"&g ...

How can I position divs in a way that the top right corner of the child div touches the bottom left corner

I am currently working on implementing a message box feature on my website. When a user clicks on the inbox icon, I want a messages box to appear, similar to how stackoverflow handles it. Stackoverflow achieves this by placing a div outside the ordered lis ...

Tips for arranging 3 tables in the right place using CSS

I have 3 tables that I utilize. My goal is to: have one on the left side of the page place one in the center of the page position one on the right side All at the same height. The issue arises when the tables expand and using float causes them to ...

Is it possible to create an index.html page with all the necessary head tags to prevent duplicate code across multiple html pages?

Imagine I am using app.js or a Bootstrap CDN link for all of my HTML pages, but I don't want to include it in every single page individually. Is there a way to create an index.html file that includes this so that all other HTML pages load the head fro ...

Managing the output from a function: Tips and strategies

Below is the function I am currently working with: function kontrola(){ var jmeno = self.document.forms.newPassForm.user.value; $.get("checkMail.php?mail="+jmeno, function(data){ if(data=='1'){ alert('Tento ...

The CSS :not selector does not work as intended

My goal is to assign the class no-color to a specific tag. When JavaScript is enabled, I want this class to be removed and the text to be colorized. However, my current CSS solution is not working as expected. Below is a sample code snippet demonstrating t ...

After creating a new Packery using AngularJS, the getElementById function may return null

Alright, so I've got this HTML markup: <button ng-click="create()">create list</button> Every time I click it, I create a new list using the Packery jQuery plugin. app.directive('packery', ['$compile', function($com ...

The body background position center does not function properly in Internet Explorer

I'm currently working on a website and facing some issues with the background-position property in CSS. Here is the code snippet that's giving me trouble: body { background-color: Black; background-image: url(images/background_ui.png); backg ...

Issue with character encoding in jQuery-ui tabs

Special characters in Swedish are replaced when configuring the tabTemplate option. For instance, using "ö" in the href attribute: var $tabs = $("#tabs").tabs('option', 'tabTemplate', '<li><a href="#ö">#{label}</ ...