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

css 中 ~ 符号、text-indent、ellipsis、ellipsis-2、text-overflow: ellipsis、::before的使用

1、~的使用直接看代码

<script setup>
</script><template><div class="container"><p><a href="javascript:;">纪检委</a><a href="javascript:;">中介为</a><a href="javascript:;">中纪委</a><a href="javascript:;">中纪委</a><a href="javascript:;">中纪委</a><a href="javascript:;">中纪委</a></p><p>CopyRight &copy; 版权所有</p></div>
</template><style scoped lang='scss'>
p {text-align: center;color: #999;padding-top: 20px;a {line-height: 1;padding: 0 10px;color: #999;display: inline-block;~a {border-left: 1px solid #ccc;}}
}
</style>

显示结果如下:

在这里插入图片描述

a~a中~a的作用就是选中a中除第一个a外的所有的a

2、text-indent的使用:


<template><a class="aTest0">测试0</a>
<a class="aTest1">测试1</a>
<div class="aTest2">测试2</div>
<div class="aTest3">测试3</div></template><style scoped lang='scss'>
.aTest0{//display: block;height: 50px;background-color: deeppink;width: 100px;text-indent: -9999px;  // 必须是块元素或者行内块元素  行内元素此属性text-indent无效
}
.aTest1{display: block;height: 50px;background-color: deeppink;width: 100px;text-indent: -9999px;
}
.aTest2{text-indent: -100px;
}</style>

效果如下:

在这里插入图片描述

3、ellipsis、ellipsis-2的使用


<template><div class="outer"><image class="left"></image><div class="aTest2"><div class="box ellipsis" >显示名字</div><div class="aTest3 ellipsis-2">这是一个对文字进行详细描述的非常长的一个长句子</div><div class="aTest3">显示金额</div><p class="box ellipsis" >显示您的详细名字</p><p class="aTest3 ellipsis-2">这是一个对文字进行详细描述的非常长的一个长句子</p><p class="aTest3">显示金额</p></div>
</div></template><style scoped lang='scss'>
.outer{width: 500px;height: 500px;background-color: pink;display: flex;align-items: center;.left{width: 400px;height: 400px;background-color: #fff;border: 1px solid gray;}.aTest2{padding-left: 10px;//overflow: hidden;}
}
</style>

显示结果:

在这里插入图片描述

把 //overflow: hidden;改成 overflow: hidden;显示如下:

在这里插入图片描述

4、text-overflow: ellipsis;的使用

单行设置:要设置四个参数

height: 20px;
white-space: nowrap; // 单行的 只需要添加个它即可
overflow: hidden;
text-overflow: ellipsis;

两行设置:要设置六个参数

height: 40px;
overflow: hidden;				//溢出内容隐藏
text-overflow: ellipsis;		//文本溢出部分用省略号表示
display: -webkit-box;			//特别显示模式
-webkit-line-clamp: 2;			//行数
-webkit-box-orient: vertical;	//盒子中内容竖直排列

整体案例:


<template><div class="outer"><image class="left"></image><div class="aTest2"><div class="wrap1"><div class="box" >显示名字</div><div class="aTest3">这是一个对文字进行详细描述的非常长的一个长句子</div><div class="aTest4">显示金额</div></div><div class="wrap2"><p class="box" >显示您的详细名字</p><p class="aTest3 ">这是一个对文字进行详细描述的非常长的一个长句子</p><p class="aTest4">显示金额</p></div></div>
</div></template><style scoped lang='scss'>
.outer{width: 500px;height: 500px;background-color: pink;display: flex;align-items: center;.left{width: 400px;height: 400px;background-color: #fff;border: 1px solid gray;}.aTest2{padding-left: 10px;overflow: hidden;.wrap1{margin-top: 10px;.aTest3{height: 40px;overflow: hidden;				//溢出内容隐藏text-overflow: ellipsis;		//文本溢出部分用省略号表示display: -webkit-box;			//特别显示模式-webkit-line-clamp: 2;			//行数-webkit-box-orient: vertical;	//盒子中内容竖直排列}}.wrap2{margin-top: 10px;.box{height: 20px;white-space: nowrap; // 单行的 只需要添加个它即可overflow: hidden;text-overflow: ellipsis;}.aTest3{height: 40px;overflow: hidden;				//溢出内容隐藏text-overflow: ellipsis;		//文本溢出部分用省略号表示display: -webkit-box;			//特别显示模式-webkit-line-clamp: 2;			//行数-webkit-box-orient: vertical;	//盒子中内容竖直排列}}}
}
</style>

显示结果:

在这里插入图片描述

5、::before 就是在当前元素前边相当于添加一个新的标签

<script setup>
</script><template><div className="container"><p><a href="javascript:;">纪检委</a><a href="javascript:;">中介为</a><a href="javascript:;">中纪委</a><a href="javascript:;">中纪委</a><a href="javascript:;">中纪委</a><a href="javascript:;">中纪委</a></p><p>CopyRight &copy; 版权所有</p></div>
</template><style scoped lang='scss'>
p {text-align: center;color: #999;padding-top: 20px;a {line-height: 1;padding: 0 10px;//text-align: center;line-height: 100px;color: #999;display: inline-block;height: 100px;position: relative;~ a::before {  // 在非第一个a标签之后的所有a标签前添加一个伪类元素,内容就是一个可以控制长短的竖线,position: absolute;top: calc((100px - 15px)/2); // 用于控制竖线的高低  100为父元素高度,15为自身高度left: 0;height: 15px;  // 用于控制竖线的长短//height: 100%;border-left: 1px solid black;content: "";}}
}
</style>

结果如下:

在这里插入图片描述

相关文章:

  • Day28笔记-Python自动化操作Word
  • 优选驾考系统小程序的设计
  • 工作日志:ruoyi-vue-plus echarts根据窗口大小变化
  • 自己做个国庆75周年头像生成器
  • 基于微信小程序的美食推荐系统
  • 数据结构-栈(理解版)
  • 数据结构之链表(2),双向链表
  • C语言——动态内存分配
  • linux部署redis,整合ansible和redis
  • 前端工程规范-2:JS代码规范(Prettier + ESLint)
  • Python 时间占位符:毫秒的使用
  • VR视频怎样进行加密和一机一码的使用?--加密(一)
  • Zookeeper下载、安装配置
  • 软件设计师——计算机网络
  • 【css】常见布局概述
  • 收藏网友的 源程序下载网
  • 2019.2.20 c++ 知识梳理
  • C++类的相互关联
  • Facebook AccountKit 接入的坑点
  • Java多线程(4):使用线程池执行定时任务
  • java正则表式的使用
  • JS创建对象模式及其对象原型链探究(一):Object模式
  • leetcode378. Kth Smallest Element in a Sorted Matrix
  • Linux中的硬链接与软链接
  • mac修复ab及siege安装
  • Node.js 新计划:使用 V8 snapshot 将启动速度提升 8 倍
  • node入门
  • Python代码面试必读 - Data Structures and Algorithms in Python
  • session共享问题解决方案
  • SSH 免密登录
  • supervisor 永不挂掉的进程 安装以及使用
  • Traffic-Sign Detection and Classification in the Wild 论文笔记
  • Vue全家桶实现一个Web App
  • vue中实现单选
  • 初探 Vue 生命周期和钩子函数
  • 猴子数据域名防封接口降低小说被封的风险
  • 机器学习 vs. 深度学习
  • - 转 Ext2.0 form使用实例
  • ​软考-高级-系统架构设计师教程(清华第2版)【第20章 系统架构设计师论文写作要点(P717~728)-思维导图】​
  • #13 yum、编译安装与sed命令的使用
  • (04)odoo视图操作
  • (4)事件处理——(2)在页面加载的时候执行任务(Performing tasks on page load)...
  • (52)只出现一次的数字III
  • (C#)Windows Shell 外壳编程系列9 - QueryInfo 扩展提示
  • (ctrl.obj) : error LNK2038: 检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“
  • (k8s)kubernetes 部署Promehteus学习之路
  • (SERIES10)DM逻辑备份还原
  • (板子)A* astar算法,AcWing第k短路+八数码 带注释
  • (附源码)apringboot计算机专业大学生就业指南 毕业设计061355
  • (附源码)计算机毕业设计SSM疫情社区管理系统
  • (黑马出品_高级篇_01)SpringCloud+RabbitMQ+Docker+Redis+搜索+分布式
  • (剑指Offer)面试题41:和为s的连续正数序列
  • ***检测工具之RKHunter AIDE
  • .bat批处理(六):替换字符串中匹配的子串
  • .bat批处理(四):路径相关%cd%和%~dp0的区别