1. Styled-Components使用

Styled-Components

1
2
3
4
5
6
7
8
9
import React from 'react';
import ReactDOM from 'react-dom';
// 在index.js中引入index.css。此时全部组件都可以使用index.css中的样式
// 但是这样不太好,因为样式容易冲突等,所以我们使用 Styled-Components
import './index.css';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

安装

1
cnpm install --save styled-components

全局样式

1
2
3
4
5
6
7
8
9
10
import { injectGlobal } from 'styled-components'

injectGlobal`
body {
margin: 0;
padding: 0;
font-family: sans-serif;
background:red;
}
`

Reset.css

目的是让样式在不同的浏览器中进行统一

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
}

https://meyerweb.com/eric/tools/css/reset/