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

前端css常用笔记

文章目录

  • 一、样式
  • 二、vue笔记
    • 2.1、组件之间的通信
      • 2.1.1 子组件调用父组件的方法
      • 2.1.2 父组件调用子组件的方法
      • 2.1.3 孙组件调用祖父组件方法的实现
    • 2.2、使用若依时,node_nodules越来越大的问题
    • 2.3、echart笔记


一、样式

  • 1 文字与图标对不齐的解决方法

    /**给icon加上这个样式即可*/
    vertical-align: -10%;
    
  • 2 让内部元素垂直水平居中
    在父级div加上这个样式

    .main{width: 100%;height: 100vh;display: flex;justify-content: center; /**水平居中*/align-items: center; /**垂直居中*/
    }
    
  • 3 禁止换行样式

    • (1) 一行不换行并显示省略号
    white-space:nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    
    • (2)自定义自能显示多少行,溢出使用省略号
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3; /*行数*
    
  • 4 小程序使图片images设置大小不变形mode='aspectFit(固定宽高)'mode='widthFix'(固定宽度并不变形)

    <!-- 固定宽高 -->
    <image src="images/wqs.png"  mode='aspectFit' style="width: 100%;"></image><!-- 固定宽度 -->
    <image src="images/wqs.png"  mode='widthFix' style="width: 100%;"></image>
    
  • 5 元素让内部元素一行显示在要在一行显示的元素加上display: inline-block;样式即可

    <!--父级元素-->
    <div><!--子级元素--><div style="display: inline-block;"></div><div style="display: inline-block;"></div>
    </div>
    
  • 6 img加上让固定宽高图片变形的样式object-fit: cover;

    <img class="avatar" src="20210914/07c92ea514be4610930c4da404ee6adb.jpg" style="object-fit: cover;">
    
  • css使img图片不变形

    object-fit: cover;
    
  • 6 去掉原始input样式

/* 去掉默认样式 */
input{border: none;outline: none;
}/* 去掉取到光标时默认的样式 */
input:focus{border: none;outline: none;
}
  • 8 原始的单选或者多选时点击文字选择选框
<!-- 单选框 -->
<label class="choice_label"><input type="radio" name="sex" value="男生"> <span>男生</span>
</label><!-- 复选框 -->
<label class="choice_label"><input type="checkbox" name="vehicle" value="我已知晓"><span>我已知晓</span>
</label>
  • 9 让内容垂直横向居中
/**父级模块*/
.main{width: 100%;height: 100vh;background-color: red;display: flex;justify-content: center;align-items: center;
}
/**子模块*/
.center{width: 500px;height: 500px;background-color: aqua;
}

二、vue笔记

2.1、组件之间的通信

2.1.1 子组件调用父组件的方法

  • 案例
// 子组件
export default {inject: ['fatherFunction'],methods:{// testfunc(){this.fatherFunction()}}
}
// 父组件
export default {inject: ['fatherFunction'],methods:{},provide () {return {fatherFunction: (item) =>{console.log('调用了父组件')}}},
}

2.1.2 父组件调用子组件的方法

  • 案例
<headerChild ref="headerChild"></headerChild>
this.$refs.headerChild.属性
this.$refs.headerChild.方法

2.1.3 孙组件调用祖父组件方法的实现

  • 在孙组件中使用inject: [‘fatherMethod’]
  • 在祖父组件中的provide里调方法
  • 例子:
<!--祖父组件-->
<template><div>祖父组件    </div>
</template>
<script>
import ServiceAreaComm from '@/components/serviceAreaComm.vue'
export default {name: 'AppraiseVisu',components: { ServiceAreaComm },data () {return {}},provide () {return {fatherMethod: (item) => this.areaParentFunc(item)}},mounted () {},methods: {// 祖父级方法areaParentFunc (id) {console.log('调用到了祖父级的方法areaParentFunc--->' + id)}}
}
</script>
<!-- 孙组件 -->
<template><div><button type="button" @click="fatherMethod">调用方法</button>    </div>
</template>
<script>
export default {name: 'AreaMenuItem',props: {},data () {return {}},inject: ['fatherMethod'],methods: {}
}
</script>

2.2、使用若依时,node_nodules越来越大的问题

原因:若依内部加入的打包的问题

解决方法:将compression-webpack-plugin 插件注释掉即可

所在位置:vue.config.js中,

const CompressionPlugin = require('compression-webpack-plugin')

2.3、echart笔记

  • 1 echarts随着窗口缩放自适应
option && this.myChart.setOption(option); // 创建好图形
window.onresize = this.myChart.resize; // 使图标自适应窗口
  • 2 销毁图形
myChart.dispose()
  • 3 创建图形与刷新图形的区别
myChart.setOption(option, true) // 刷新数据(刷新数据时不需要销毁图形)
myChart.setOption(option) // 创建数据
http://www.lryc.cn/news/402962.html

相关文章:

  • WINUI或WPF灵活使用样式、控件模板、自定义控件、用户控件
  • 如何用EXCEL自动解方程/方程组?利用 矩阵乘法X=A-*B,X=mmult(minverse(A), B)
  • ComfyUI进阶:Comfyroll插件 (二)
  • Spring Boot集成Activity7实现简单的审批流
  • 自动驾驶,革了谁的命
  • 在线实习项目|泰迪智能科技企业级项目学习,暑期大数据人工智能学习
  • 【BUG】已解决:To update, run: python.exe -m pip install --upgrade pip
  • Lua 运算符
  • 园区道路车辆智能管控视频解决方案,打造安全畅通的园区交通环境
  • MATLAB R2023b下载安装教程汉化中文版设置
  • Java二十三种设计模式-工厂方法模式(2/23)
  • 【iOS】OC类与对象的本质分析
  • 【机器学习】使用Python的dlib库实现人脸识别技术
  • GitHub 令牌泄漏, Python 核心资源库面临潜在攻击
  • 【面试题】Golang 锁的相关问题(第七篇)
  • 深入剖析CommonJS modules和ECMAScript modules
  • 角点检测及MATLAB实现
  • TypeScript导学:从零开始
  • 【BUG】已解决:IndexError: list index out of range
  • AWS-S3实现Minio分片上传、断点续传、秒传、分片下载、暂停下载
  • Selenium - 设置元素等待及加载策略
  • 【数据结构】线性结构——数组、链表、栈和队列
  • json将列表字典等转字符串,然后解析又转回来
  • 记录|.NET上位机开发和PLC通信的实现
  • 微服务实战系列之玩转Docker(二)
  • Linux:信号的概念与产生
  • 云监控(华为) | 实训学习day2(10)
  • 数据结构第35节 性能优化 算法的选择
  • 每天一个数据分析题(四百三十六)- 正态分布
  • 跟我学C++中级篇——虚函数的性能