Comments (2)
Semantic UI + Styled Component
- Semantic UIとかで用意されているコンポーネントのCSSをStyled Componentで上書きできる
- たぶんMaterial UIとかでも同じようにいける
CSSの更新方法
styled()
を使う
import styled from 'styled-component';
const Button = styled.button`
color: palevioletred;
font-size: 1em;
margin: 1em;
padding: 0.25em 1em;
border: 2px solid palevioletred;
border-radius: 3px;
`;
// こんな感じで更新できる
const TomatoButton = styled(Button)`
color: tomato;
border-color: tomato;
`;
Semantic UIでも同じように可能
import { Button } from 'semantic-ui-react';
const TomatoButton = styled(Button)`
color: tomato;
border-color: tomato;
`;
子要素にもCSSを適用するには
Card
だけでなくCard.Content
まで
import { Card } from 'semantic-ui-react';
<StyledCard>
<StyledCard.Content>
{...}
</StyledCard.Content>
</StyledCard>
const StyledCard = styled(Card)`
cursor: pointer;
// こんな感じで子要素のCSSを直接指定する
&&&.ui.card .content {
padding-right: 0;
padding-left: 0;
}
`;
分からないこと
<Card as={Link}>
みたいなときにCSSが適用されなくなってしまうのでどう対処するのがスマートだったか?- すべてがタグにとして扱われてしまった
- 以下のように対処した
//これはCSSがうまく適用されなかった
<StyledCard as={Link} to="/" />
//これだとOK
<Link>
<StyledCard />
</Link>
参照
from sns-merng.
Styled ComponentでのCSSのoverride
- Styled Componentでは
!important
は使ってはいけない(なぜ?) - 代わりに
&&&
を使う(これはCSSの詳細度を上げる操作)
//これはダメ
const MyStyledComponent = styled(AlreadyStyledComponent)`
color: palevioletred !important;
font-weight: bold !important;
`
//これが正しい
const MyStyledComponent = styled(AlreadyStyledComponent)`
&&& {
color: palevioletred;
font-weight: bold;
}
`
- ただ、そもそも
!important
を使わない設計にすべき- 外部のデザインライブラリを使用するなら使う場面出てくるかも
参照
from sns-merng.
Related Issues (3)
- 調べたことのメモ(主にApollo + MongoDBのこと) HOT 12
- GraphQLのこと HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sns-merng.