IE下input placeholder的字体大小及颜色设置

  1. 首先IE9不支持placeholder属性;
  2. IE10和Edge下的placeholder设置不了颜色和大小;

但是看了小米官网的注册就是可以的,请问如何做到IE9+以上的placeholder兼容性

阅读 4k
2 个回答
新手上路,请多包涵

用label标签伪造出placeholder,当onfocus时消失即可

纯HTML+CSS,貌似比placeholder属性兼容还好?,虽然还不够完美~

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style type="text/css">
    .input {
      width: 169px;
      -webkit-appearance: textfield;
      background-color: white;
      -webkit-rtl-ordering: logical;
      cursor: text;
      padding: 1px;
      border-width: 2px;
      border-style: inset;
      border-color: initial;
      border-image: initial;
      text-rendering: auto;
      color: rgb(128, 114, 114);
      letter-spacing: normal;
      word-spacing: normal;
      text-transform: none;
      text-indent: 0px;
      text-shadow: none;
      text-align: start;
      margin: 0em;
      font: 400 13.3333px Arial;
    }
    .input:empty:not(:focus)::before {
      content: attr(data-placeholder);
    }
  </style>
</head>
<body>

  <div class="input" contenteditable data-placeholder="请输入文字"></div>

  <input type="text" placeholder="请输入文字" />

</body>
</html>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题