My text input placeholders refuse to display in IE and Firefox despite having used the -moz-placeholder attribute. This can be viewed on the contact page here if you are using Firefox or IE.

尽管使用了-moz-placeholder属性,但我的文本输入占位符拒绝在IE和Firefox中显示。如果您使用的是Firefox或IE,可以在此处的联系页面上查看。

Can someone please help I have been trying to figure this out for weeks. A sample of my code is below:

有人可以帮助我一直试图弄清楚这几周。我的代码示例如下:

 input::-moz-placeholder, textarea::-moz-placeholder {
    color: #aaa;
    font-size: 18px;
}

    input:-ms-input-placeholder, textarea::-ms-input-placeholder {
        color: #aaa;
        font-size: 18px;
    }

input::-webkit-input-placeholder, textarea::-webkit-input-placeholder {
    color: #aaa;
    font-size: 18px;
}

4 个解决方案

#1


38

As luke2012 stated this happens when box-sizing: border-box; is being used on text type input fields. However this only happens when a fixed height is being used (such as in the Bootstrap framework) and there is too much top and bottom padding. Which not only prevents placeholder text from displaying but also input text as well in Firefox.

正如luke2012所说,当盒装尺寸发生时会发生这种情况:边框盒;正在用于文本类型输入字段。然而,这仅在使用固定高度时(例如在Bootstrap框架中)并且顶部和底部填充太多时才会发生。这不仅可以防止占位符文本显示,还可以在Firefox中输入文本。

I find that the better solution is to keep box-sizing: border-box; and to instead remove the top and bottom padding and increase the height to the total height that you want the input field to have (including any border).

我发现更好的解决方案是保持盒子大小:边框盒;而是删除顶部和底部填充,并将高度增加到您希望输入字段具有的总高度(包括任何边框)。

input[type="email"], input[type="password"], input[type="text"] 
{
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
    height: 42px; // Increase height as required
    margin-bottom: 30px;
    padding: 0 20px; // Now only left & right padding
}

This keeps things more consistent and works well on frameworks such as Bootstrap.

这使事情更加一致,并且在Bootstrap等框架上运行良好。

Alternatively, you could increase the fixed height or set height: auto; and adjust the top and bottom padding as required.

或者,您可以增加固定高度或设置高度:auto;并根据需要调整顶部和底部填充。

更多相关文章

  1. 当页面上有多个按钮时,按钮样式在页面加载上有厚的边框
  2. Div高度为图像高度,图像宽度为div宽度
  3. 在textarea上应用0高度div的类
  4. 获取html DOM元素内容的边框
  5. 扩展子div时如何扩展容器div的高度
  6. textarea高度自适应自动展开
  7. android在onCreate()方法中获取View的宽度与高度的方法实战
  8. Android 自定义控件高度设置onMeasure方法
  9. 圆形边框一边只有java

随机推荐

  1. 深入React
  2. 今晚,我等你 ~
  3. 分布式系统的事务处理
  4. 都想学大数据开发?年轻人耗子尾汁吧~
  5. 今天的南京,很冷很冷
  6. vertical-align刨根问底
  7. CSS上下左右居中
  8. 适配了ARM M1芯片的IDEA和Java到底有多野
  9. 由12306.cn谈谈网站性能技术
  10. 武汉有哪些牛批的互联网公司?