简体   繁体   English

有没有办法设置边框颜色和文本颜色的样式<TextField/>在 Material-UI 中不使用 makeStyles

[英]Is there a way to style the border color and text color of <TextField/> in Material-UI without using makeStyles

Is it possible to style Material-UI without using the makeStyles feature, for example, css?是否可以在不使用 makeStyles 功能(例如 css)的情况下设置 Material-UI 的样式? Just trying to understand how Material-UI style works.只是想了解 Material-UI 风格是如何工作的。

The red style on the bottom is the style I'm trying to achieve with simple css here.底部的红色样式是我在这里尝试用简单的 css 实现的样式。

在此处输入图片说明

Below is an example of how to customize the various colors in an outlined select using simple CSS.下面是一个示例,说明如何使用简单的 CSS 自定义轮廓选择中的各种颜色。

styles.css样式文件

.customSelect {
  width: 200px;
}
.customSelect .MuiInputLabel-root {
  color: red;
}
.customSelect .MuiInputBase-input {
  color: green;
}
.customSelect .MuiOutlinedInput-notchedOutline {
  border-color: red;
}
.customSelect:hover .MuiOutlinedInput-notchedOutline {
  border-color: orange;
}
.customSelect
  .MuiOutlinedInput-root.Mui-focused
  .MuiOutlinedInput-notchedOutline {
  border-color: purple;
}
.customSelectMenu .MuiMenuItem-root {
  color: blue;
}

App.js应用程序.js

import React from "react";
import "./styles.css";
import TextField from "@material-ui/core/TextField";
import MenuItem from "@material-ui/core/MenuItem";

export default function App() {
  const [value, setValue] = React.useState("");
  return (
    <TextField
      className="customSelect"
      label="Sale Type"
      required
      select
      value={value}
      onChange={event => setValue(event.target.value)}
      variant="outlined"
      SelectProps={{ MenuProps: { className: "customSelectMenu" } }}
    >
      <MenuItem value={1}>Sale Type 1</MenuItem>
      <MenuItem value={2}>Sale Type 2</MenuItem>
    </TextField>
  );
}

通过 CSS 编辑自定义 TextField

Related answers:相关回答:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM