当前位置: 首页 > news >正文

海宁网站制作专业网站优化排名

海宁网站制作,专业网站优化排名,网站建设的缺陷,网页版梦幻西游探案寻奇攻略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.css'class 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 'react'import { Container } from './style.js'class HighCom extends PureComponent {render() {return (<Container><div className='title' > css in js </div></Container>)}}export default HighCom
继承
import styled from "styled-components";
export const Container = styled.div`font-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 className='title' > css in js </div></Container>)}
}
export default HighCom
  • css in js
import styled from "styled-components";export const Container = styled.div`
.title{font-size: ${props=>props.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: ${props=>props.fontSize}px;font-weight: 600;color: ${titleColor};
}`
http://www.hkea.cn/news/40701/

相关文章:

  • 北京做百度网站建设电商平台如何推广运营
  • 电脑个人网站怎么做网络销售新手入门
  • 海口网站建设 小黄网络手机百度搜索
  • 太原百度网站建设网站应该如何进行优化
  • 烟台市做网站uc浏览网页版进入
  • 工程信息网站哪家做的较好提高工作效率心得体会
  • 建站平台入口徐州网站设计
  • 出口手工艺品网站建设方案站长统计app下载
  • 提升学历骗局武汉搜索引擎排名优化
  • wordpress+park主题上海全国关键词排名优化
  • 潍坊最早做网站的公司短链接生成网址
  • 东莞化工网站建设爱站网ip反域名查询
  • 做网站赚钱 2017哈尔滨关键词排名工具
  • 建设的网站首页微信怎么做推广
  • 建设网站导航百度信息流推广和搜索推广
  • 深圳室内设计公司招聘信息流广告优化
  • 旅游网站首页四种营销模式
  • 负责网站建设如何在百度发广告推广
  • 联通的网站是谁做的营销的主要目的有哪些
  • 衡阳微信网站地推的方法和技巧
  • 南阳做网站公司哪家好自动发外链工具
  • 潍坊网站制作最低价格网络营销案例有哪些
  • 做网站有谁做谷歌seo视频教程
  • 资深的网站推广完美日记网络营销策划书
  • 90设计网站免费素材网站seo培训
  • 整形美容网站源码上海seo优化bwyseo
  • 武威市住房和建设局网站百度app下载安装普通下载
  • 网站物理结构天津百度推广排名
  • 美容平台网站建设百度指数查询移动版
  • 工程公司手机网站建立网站怎么搞