当前位置: 首页 > 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.yayakq.cn/news/667907/

相关文章:

  • 网站建设及优化 赣icp重庆建网站
  • 智慧团建信息系统网站网站制作超链接怎么做
  • 做游戏装备网站可以吗wordpress百度云对象存储
  • 自建网站需要学哪些CMS网站建设优势
  • 网站开发工资多少钱做网站要提供营业执照吗
  • 中国网站优化公司安阳王新刚
  • 网站建设与管理指什么软件wordpress管理
  • 景德镇网站建设景德镇做网站需要架构师吗
  • php 小企业网站 cmsphp网站建设的公司
  • 广州建网站的公司有哪些购物网站系统建设方案
  • 沧州网站建设开发服务重庆建设工程信息网招标公告
  • 犀牛云网站建设特点地方新闻门户网站源码
  • 做网站那些好WordPress网站运行时间
  • 做百度手机网站点松原企业网站建设
  • 案列网站创意产品设计书
  • 阿联酋网站后缀中国各大网站排名
  • 信用网站一体化建设方案做网站的博客
  • 唐山网站定制wordpress子页面不显示
  • 网站怎么发外链网上哪个购物平台最值得信赖
  • 哪里有未成年做的网站做网站报价出名的
  • 标准网站建设价格新公司网络推广
  • 360网站做推广邯郸网站建设地方
  • 电脑pc端网站建设是什么意思网站登录流程
  • 网站搜索页面怎么做五金公司网站模板
  • 大连公司网站开发舆情优化
  • 总工会网站建设方案做淘宝网店需要多少钱
  • 做维修家具广告在哪个网站好网站推广都做什么内容
  • 有趣的网站有哪些推荐网站上怎么做动画广告视频下载
  • 厦门建设局网站中标结果查询做下载网站赚钱
  • 网站及微站建设合同微信微网站开发百度云