javascript - 使用 css 在 react 选择中设置我的占位符样式

标签 javascript html css reactjs redux

  • 我是 React Select 的新手。
  • 我正在尝试使用 CSS 设置占位符的样式
  • 所以我在沙盒中构建了一个原型(prototype)。
  • 我尝试使用 CSS 更改占位符的颜色。
  • 我给了红色,但还是没有覆盖
  • 你能告诉我如何解决吗?
  • 在下面提供我的沙箱和代码片段。

  • 即使我在 google 上搜索占位符 css,也得到了这个链接,但仍然没有帮助我

https://www.w3schools.com/cssref/sel_placeholder.asp

https://codesandbox.io/s/react-codesandboxer-example-1q8nd

<Select
    defaultValue={""}
    label="Single select"
    placeholder={" Placeholder test "}
    options={flavourOptions}
    theme={theme => ({
      ...theme,
      borderRadius: 0,
      colors: {
        ...theme.colors,
        primary25: "hotpink",
        primary: "black",
        background: "red",
        color:"red",
      }
    })}
  />

最佳答案

根据 react-select文档,占位符颜色的 neutral50 响应。

试试这个:

<Select
  defaultValue={""}
  label="Single select"
  placeholder={" Placeholder test "}
  options={flavourOptions}
  theme={theme => ({
    ...theme,
    borderRadius: 0,
    colors: {
      ...theme.colors,
      neutral50: 'red',  // Placeholder color
    }
  })}
/>

或者你可以简单地做如下:

export default () => {
  return (
    <div>
      <p>
        We see that the final rendered output is not an input box, but rather a
        set of divs with certain classes applied on them... so we just change
        the class
      </p>
      <Select
        defaultValue={""}
        label="Single select"
        placeholder="Placeholder test"
        styles={colorStyles}
        options={flavourOptions}
      />
    </div>
  );
};

const colorStyles = {
  placeholder: defaultStyles => {
    return {
      ...defaultStyles,
      color: "blue"
    };
  }
};

检查这个例子:Example

关于javascript - 使用 css 在 react 选择中设置我的占位符样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59314742/

相关文章:

javascript - 带小数和单位的负/正值

html - 如何获取显示 HTML 源代码的链接?

javascript - 带定时器自动关闭弹出窗口

html - flexbox 半侧布局,左侧图像固定

javascript - "!function () {}"在 JavaScript 中的含义/作用是什么?

javascript - 如何使用 JavaScript 获取本地文件夹内容

php - setInterval 内的 JavaScript setTimeout

javascript - React Router 处理 onEnter 的逻辑是什么?

html - 在 IE7 中导航没有正确显示

css - 在我的 View XHTML 中包含 CSS