使用styled-components初始化css
生活随笔
收集整理的這篇文章主要介紹了
使用styled-components初始化css
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.安裝
yarn add styled-components
2.創(chuàng)建style.js
import {createGlobalStyle} from 'styled-components'
// 導(dǎo)出的變量要大寫開頭
export const CreateStyle = createGlobalStyle`
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
Previous Version
`
3.在主組件里使用
import React, { Component } from 'react';
import {CreateStyle} from './style'
class Test extends Component {
constructor(props) {
super(props);
this.state = { }
}
render() {
return (
<div>
<CreateStyle></CreateStyle>
</div>
);
}
}
export default Test;
總結(jié)
以上是生活随笔為你收集整理的使用styled-components初始化css的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 22 块级元素和行内元素
- 下一篇: 访问数据库优化