【问题标题】:Remove left indentation or unknown padding from HTML select element options从 HTML 选择元素选项中删除左缩进或未知填充
【发布时间】:2015-12-06 01:39:54
【问题描述】:

我正在构建一个注册表单,但在左对齐 input[type="text"] placeholder<select> 元素的“伪”占位符时遇到问题。我希望 input[type="text"] 占位符与 <select> 的“伪”占位符对齐。

我对选择的 HTML 元素使用了“伪”占位符这个词,因为选择的 HTML 元素没有占位符,并且显示的内容而不是占位符是选择中的第一个选项。

您可以在屏幕截图中看到一个 select HTML 元素,其中第一个 <option> 文本为“Country”。还有另一个选择元素,第一个选项文本是“你多久想要你的书?”。

与 input[type="text"] 占位符文本相比,这两个选择元素都有一个缩进,我不能与 input[type="text"] 占位符文本完全左对齐。

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" />

【问题讨论】:

标签: jquery html css


【解决方案1】:

我已尝试重新创建它,但我仅在 Firefox 上发现了“错误”。 如果是这样的话,这里发生的就是声明

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

在用户代理样式中找到。 See here how to inspect that

不过,如果您在 CSS 中为 select &gt; option 覆盖它,它就不起作用。

 /** IF you add the following
     in your CSS, it won't solve 
     the problem
 **/

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

我的猜测是实际显示填充的元素是一个“幽灵”元素,它是 &lt;option&gt; 元素的副本,因此它不是您的 css 的目标。

这是一个非常丑陋的解决方案

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;
}

And you can see it here

这基本上会在每个输入左侧添加 3px,在 FF 上这将使选项缩进 6px ,因此我们仅为 select 元素重置它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    • 2018-01-08
    • 2014-09-13
    相关资源
    最近更新 更多