【问题标题】:How can I change the placeholder color in Ant Design's Select component?如何更改 Ant Design Select 组件中的占位符颜色?
【发布时间】:2019-05-12 00:46:24
【问题描述】:

我想在 Ant Design 中更改 Select 组件的占位符颜色。

我已经在下面尝试了这些,但它们都不起作用。

.ant-select-selection {
  :placeholder-shown {
    color: red !important;
  }
  &:placeholder-shown {
    color: red !important;
  }
  :::placeholder {
    color: red !important;
  }
  color: black !important;
  &::-webkit-input-placeholder {
    color: blue !important;
  }
  &:placeholder {
    color: blue !important;
  }
  :placeholder {
    color: blue !important;
  }
  ::-webkit-input-placeholder {
    color: blue !important;
  }
}

::-webkit-input-placeholder {
  color: blue !important;
}

【问题讨论】:

    标签: antd


    【解决方案1】:

    我尝试了 Hemanthvrm 的建议,但似乎他们在 Ant Design 4 中将占位符元素的类名更改为 .ant-select-selection-placeholder。对我有用的是以下内容:

    .ant-select-selection-placeholder {
      color: #f0f0f0;
    }
    

    请注意,默认情况下占位符元素上有一个opacity: 0.4;,因此无论您使用什么颜色都会显得淡出。

    还要注意,这种占位符样式行为在不同的 Ant 组件中是不一致的。例如,要设置日期范围选择器的占位符的样式,我必须执行以下操作:

    .ant-picker-input input::placeholder {
      color: #f0f0f0;
    }
    

    坏消息是,所有这些名称可能会在新的主要版本中再次更改。所以最好在一个文件中声明所有与 Ant 相关的样式,这样您的项目就可以轻松地适应这些变化。

    【讨论】:

      【解决方案2】:

      这会起作用

      .ant-select-selection__placeholder{
        color : blue;
      }
      

      工作样本 https://codesandbox.io/s/139lnkwwm3

      【讨论】:

      • 这似乎可行,谢谢。我只是想知道,我认为像__placeholder 这样的东西是由 Antd 自动生成的,使用起来不可靠吗?这是“正确”的做法吗?
      • 完全没问题,你可以在这里阅读pro.ant.design/docs/style ..照顾全球污染
      猜你喜欢
      • 2020-11-16
      • 2021-02-25
      • 2018-09-05
      • 2019-04-26
      • 1970-01-01
      • 2019-02-21
      • 2019-10-09
      • 1970-01-01
      • 2012-04-12
      相关资源
      最近更新 更多