美文网首页
1.项目搭建Styled-components与Reset.cs

1.项目搭建Styled-components与Reset.cs

作者: 你坤儿姐 | 来源:发表于2019-06-03 16:49 被阅读0次

代码见https://gitee.com/XiaoKunErGe/JianShu.git历史第四次提交

一.创建项目

npx create-react-app jianshu
cd jianshu
npm start

二.删除不必要的代码

在src文件夹下,只保留App.js、index.js,添加style.js
在App.js中删除div标签下所有代码,在index.js中删除serviceWorker,删除index.css中所有代码。

三.使用Styled-components和Reset.css

yarn add styled-components
在style.js中创建GlobalStyle

import { createGlobalStyle } from 'styled-components';

export const GlobalStyle = createGlobalStyle`

`

到到百度搜索react.scc,打开### CSS Tools: Reset CSS
复制代码到

import { createGlobalStyle } from 'styled-components';

export const GlobalStyle = 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;
}
`;

在App.js中引入
import { GlobalStyle } from './style';

function App() {
  return (
    <div>
      <GlobalStyle/>
      Hello world
    </div>
  );
}
export default App;

相关文章

网友评论

      本文标题:1.项目搭建Styled-components与Reset.cs

      本文链接:https://www.haomeiwen.com/subject/wjwcxctx.html