美文网首页
style-components的使用

style-components的使用

作者: 易路先登 | 来源:发表于2020-04-04 22:46 被阅读0次

style-components是使css实现模块化的
使用:
1 安装

npm install styled-components

2 (1)全局样式
首先创建全局样式文件,以.js为后缀

import { createGlobalStyle } from "styled-components";

const GlobalStyle = createGlobalStyle`
body {
    line-height: 1;
}
`
export default GlobalStyle;

引用:在对应组件内使用<GlobalStyle/>引入即可

import  GlobalStyle from "./style.js";

ReactDOM.render(
  
    <>
      <其他组件>
      <GlobalStyle/>
    </>,
  document.getElementById('root')
);

3 样式组件

export const Nav = styled.div`
    width:960px;
    height:100%;
    padding-right:70px;
    box-sizing:border-box;
    margin:0 auto;
`

如果需要在div标签上添加属性:

export const Nav = styled.div.attrs({
    index:10
})`
    width:960px;
    height:100%;
    padding-right:70px;
    box-sizing:border-box;
    margin:0 auto;
`

相关文章

  • style-components的使用

    style-components是使css实现模块化的使用:1 安装 2 (1)全局样式首先创建全局样式文件,以....

  • style-components

    styled-components 虽然 可能 能提升了开发体验,但是它运行时(runtime)的机制却对性能有损...

  • 2.使用style-components完成header组件布局

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

  • iconfont的使用(下载使用)

    1、下载文件 2、在生命周期中引入项目 beforeCreate () { var domModule = ...

  • Gson的使用--使用注解

    Gson为了简化序列化和反序列化的过程,提供了很多注解,这些注解大致分为三类,我们一一的介绍一下。 自定义字段的名...

  • 记录使用iframe的使用

    默认记录一下----可以说 这是我第一次使用iframe 之前都没有使用过; 使用方式: 自己开发就用了这几个属...

  • with的使用

    下面例子可以具体说明with如何工作: 运行代码,输出如下

  • this的使用

    什么是this? this是一个关键字,这个关键字总是返回一个对象;简单说,就是返回属性或方法“当前”所在的对象。...

  • this的使用

    JS中this调用有几种情况 一:纯粹的函数调用 这是函数的最通常用法,属于全局性调用,因此this就代表全局对象...

  • ==的使用

    积累日常遇到的编码规范,良好的编码习惯,持续更新。。。 日常使用==用于判断的时候,习惯性将比较值写前面,变量写后...

网友评论

      本文标题:style-components的使用

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