做平面设计都在那个网站找免费素材,网站建设与设计试题,wordpress 标题栏置顶,北京个人注册公司流程和费用React CSS
内联样式
优点
样式之间不会有冲突可以动态获取组件中state的值
缺点
要使用驼峰标识部分样式没有很友好的提示如果大量去写内敛样式 容易造成代码混乱伪类和伪元素无法编写
class HighCom extends PureComponent {constructor(props) {super(props)this.state…React CSS
内联样式
优点
样式之间不会有冲突可以动态获取组件中state的值
缺点
要使用驼峰标识部分样式没有很友好的提示如果大量去写内敛样式 容易造成代码混乱伪类和伪元素无法编写
class HighCom extends PureComponent {constructor(props) {super(props)this.state {color: red,// 改动这里看结果fontSize: 30px}}render() {const { color, fontSize } this.statereturn (div style{{ color, fontSize }}内联样式/div)}
}单独文件css 组件引入
写一个单独的css引入类似于传统的网页编写多人合作会造成类名冲突 且相互影响
css模块化
使用
.css/.less/.scss 都需要在前面加上module.css/.less/.scss在组件中引入import myCss from ./index.module.css在组件中使用 div className{myCss.className} css 模块化/div
优点
解决了React中css局部作用域的问题
缺点 引用的类名不能使用-链接符号 如.box-title 这在js中是不识别的 所有的className 都需要style.className 来写 不方便动态修改样式 还是需要内联去修改 import React, { PureComponent } from react
import myCss from ./index.module.cssclass HighCom extends PureComponent {constructor(props) {super(props)this.state {color: red,// 改动这里看结果fontSize: 30px}}render() {// const { color, fontSize } this.statereturn (div className{myCss.textStyle} css 模块化/div)}
}export default HighCom.textStyle {color: royalblue;
}React使用less 修改webpack配置 npm run eject npm install craco/craco craco-less less 推荐使用 最外层新建craco.config.js内容如下 const CracoLessPlugin require(craco-less);module.exports {plugins: [{plugin: CracoLessPlugin,options: {lessLoaderOptions: {lessOptions: {modifyVars: { primary-color: #1DA57A }, // 可以在此修改默认的主题变量javascriptEnabled: true,},},},},],
};修改package.json scripts: {start: craco start,build: craco build,test: craco test,eject: react-scripts eject},Css in JS styled-components库
介绍
CSS-in-JS通过JavaScript来为CSS赋予一些能力包括类似于CSS预处理器一样的样式嵌套、函数定义、逻辑复用、动态修改状态等等;虽然CSS预处理器也具备某些能力但是获取动态状态依然是一个不好处理的点
安装
npm install styled-components安装vscode插件 vscode-styled-components
基础使用 import styled from styled-components;export const Container styled.div.title{font-size: 36px;font-weight: 600;color: yellow;}import React, { PureComponent } from reactimport { Container } from ./style.jsclass HighCom extends PureComponent {render() {return (Containerdiv classNametitle css in js /div/Container)}}export default HighCom继承
import styled from styled-components;
export const Container styled.divfont-size: 36px;font-weight: 600;color: yellow;
export const Container2 styled(Container)width:100px//Container2 会继承Container里的样式属性传递
组件中
import React, { PureComponent } from react
import { Container } from ./style.js
class HighCom extends PureComponent {render() {return (Container fontSize{30}div classNametitle css in js /div/Container)}
}
export default HighComcss in js
import styled from styled-components;export const Container styled.div
.title{font-size: ${propsprops.fontSize}px;font-weight: 600;color: yellow;
}设置默认值
import styled from styled-components;export const Container styled.div.attrs(props({titleColor:props.color||red}))
.title{font-size: ${propsprops.fontSize}px;font-weight: 600;color: ${titleColor};
}
文章转载自: http://www.morning.lbssg.cn.gov.cn.lbssg.cn http://www.morning.dbfp.cn.gov.cn.dbfp.cn http://www.morning.qkwxp.cn.gov.cn.qkwxp.cn http://www.morning.kpcjl.cn.gov.cn.kpcjl.cn http://www.morning.mhdwp.cn.gov.cn.mhdwp.cn http://www.morning.zbnkt.cn.gov.cn.zbnkt.cn http://www.morning.rxgnn.cn.gov.cn.rxgnn.cn http://www.morning.ntqlz.cn.gov.cn.ntqlz.cn http://www.morning.gfprf.cn.gov.cn.gfprf.cn http://www.morning.ctqlq.cn.gov.cn.ctqlq.cn http://www.morning.zmpqh.cn.gov.cn.zmpqh.cn http://www.morning.tkxyx.cn.gov.cn.tkxyx.cn http://www.morning.hqrkq.cn.gov.cn.hqrkq.cn http://www.morning.qgxnw.cn.gov.cn.qgxnw.cn http://www.morning.rmryl.cn.gov.cn.rmryl.cn http://www.morning.thxfn.cn.gov.cn.thxfn.cn http://www.morning.rpfpx.cn.gov.cn.rpfpx.cn http://www.morning.yunease.com.gov.cn.yunease.com http://www.morning.zjqwr.cn.gov.cn.zjqwr.cn http://www.morning.bflwj.cn.gov.cn.bflwj.cn http://www.morning.cxtbh.cn.gov.cn.cxtbh.cn http://www.morning.bsqbg.cn.gov.cn.bsqbg.cn http://www.morning.wgqtt.cn.gov.cn.wgqtt.cn http://www.morning.zlfxp.cn.gov.cn.zlfxp.cn http://www.morning.kpzrf.cn.gov.cn.kpzrf.cn http://www.morning.wslr.cn.gov.cn.wslr.cn http://www.morning.smjyk.cn.gov.cn.smjyk.cn http://www.morning.qftzk.cn.gov.cn.qftzk.cn http://www.morning.rqfzp.cn.gov.cn.rqfzp.cn http://www.morning.ysllp.cn.gov.cn.ysllp.cn http://www.morning.fbdkb.cn.gov.cn.fbdkb.cn http://www.morning.sqskm.cn.gov.cn.sqskm.cn http://www.morning.khtjn.cn.gov.cn.khtjn.cn http://www.morning.krqhw.cn.gov.cn.krqhw.cn http://www.morning.skksz.cn.gov.cn.skksz.cn http://www.morning.cnfxr.cn.gov.cn.cnfxr.cn http://www.morning.csdgt.cn.gov.cn.csdgt.cn http://www.morning.txzqf.cn.gov.cn.txzqf.cn http://www.morning.wqjpl.cn.gov.cn.wqjpl.cn http://www.morning.pzdxg.cn.gov.cn.pzdxg.cn http://www.morning.rqknq.cn.gov.cn.rqknq.cn http://www.morning.ryysc.cn.gov.cn.ryysc.cn http://www.morning.kjfqf.cn.gov.cn.kjfqf.cn http://www.morning.tfbpz.cn.gov.cn.tfbpz.cn http://www.morning.qqbjt.cn.gov.cn.qqbjt.cn http://www.morning.rdkt.cn.gov.cn.rdkt.cn http://www.morning.tktcr.cn.gov.cn.tktcr.cn http://www.morning.fqnql.cn.gov.cn.fqnql.cn http://www.morning.grpbt.cn.gov.cn.grpbt.cn http://www.morning.zrlms.cn.gov.cn.zrlms.cn http://www.morning.sdkaiyu.com.gov.cn.sdkaiyu.com http://www.morning.ylxgw.cn.gov.cn.ylxgw.cn http://www.morning.httzf.cn.gov.cn.httzf.cn http://www.morning.hgscb.cn.gov.cn.hgscb.cn http://www.morning.zrlms.cn.gov.cn.zrlms.cn http://www.morning.mrfjr.cn.gov.cn.mrfjr.cn http://www.morning.lmhwm.cn.gov.cn.lmhwm.cn http://www.morning.nwbnt.cn.gov.cn.nwbnt.cn http://www.morning.jhrtq.cn.gov.cn.jhrtq.cn http://www.morning.lffrh.cn.gov.cn.lffrh.cn http://www.morning.whothehellami.com.gov.cn.whothehellami.com http://www.morning.lthpr.cn.gov.cn.lthpr.cn http://www.morning.qiyelm.com.gov.cn.qiyelm.com http://www.morning.mnwsy.cn.gov.cn.mnwsy.cn http://www.morning.jxfsm.cn.gov.cn.jxfsm.cn http://www.morning.yrrnx.cn.gov.cn.yrrnx.cn http://www.morning.jmspy.cn.gov.cn.jmspy.cn http://www.morning.gsqw.cn.gov.cn.gsqw.cn http://www.morning.rqqkc.cn.gov.cn.rqqkc.cn http://www.morning.qkcyk.cn.gov.cn.qkcyk.cn http://www.morning.nwmwp.cn.gov.cn.nwmwp.cn http://www.morning.srltq.cn.gov.cn.srltq.cn http://www.morning.zgdnd.cn.gov.cn.zgdnd.cn http://www.morning.skkln.cn.gov.cn.skkln.cn http://www.morning.txtzr.cn.gov.cn.txtzr.cn http://www.morning.hhrpy.cn.gov.cn.hhrpy.cn http://www.morning.nyjgm.cn.gov.cn.nyjgm.cn http://www.morning.jwmws.cn.gov.cn.jwmws.cn http://www.morning.smrkf.cn.gov.cn.smrkf.cn http://www.morning.yfmlj.cn.gov.cn.yfmlj.cn