0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

react + styled-components + material-ui スタイルが効かない

Last updated at Posted at 2021-06-25

styled-componentsでスタイルをあてるとき

通常

const StyledDiv = styled.div`
  background-color: #f5f5f7;
  width: 100%;
  height: 100px;
`;

html要素にあてるときは公式通りの使い方でおk

material-uiのコンポーネントにあてるときも基本は公式通りでいい

import { Box } from "@material-ui/core";

const StyledBox = styled(Box)`
  background-color: #f5f5f7;
  width: 100%;
  height: 100px;
`;

例外パターン

import { Button } from "@material-ui/core";

const StyledBox = styled(Button)`
  background-color: #f5f5f7;
  width: 100%;
  color:#fff; /*これは効かない*/
`;

material-uiのスタイルのデフォルト値は普通に整形しても変更が効かない場合がある。

import { Button } from "@material-ui/core";

const StyledBox = styled(Button)`
  background-color: #f5f5f7;
  width: 100%;
  height:100px;
  color:#fff !important; /*これは効く*/
`;

ゴリ押しでやるならこれでも可。

ちゃんとやるなら
オーバーライド勉強しないとだめ?

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?