应无所住,而生其心
排名
1
文章
860
粉丝
112
评论
163
net core webapi post传递参数
庸人 : 确实坑哈,我也是下班好了好几次,发现后台传递对象是可以的,但...
百度编辑器自定义模板
庸人 : 我建议换个编辑器,因为现在百度富文本已经停止维护了,用tinymec...
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术

css实现侧边栏中树枝的效果

2651人阅读 2020/8/15 18:06 总访问:5182783 评论:0 收藏:0 手机
分类: 前端

效果如下

就是这种侧边栏中间那一块的效果:

具体效果如下:


左边的虚线是利用ul左边框实现的:border-left: 1px dashed #ccccd8


横着的虚线就是利用里边的一个div实现的,也是通过边框来实现的。


这样写后上面和下面都会冒出来一截枝枝,我们利用伪类选择器在上面和下面生成一个元素来挡住冒出来的枝枝就行了

具体完成的代码如下:

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. body {
  9. margin: 0px;
  10. padding: 0px;
  11. }
  12. .aside-content {
  13. max-height: 238px;
  14. overflow: hidden;
  15. -webkit-box-sizing: border-box;
  16. box-sizing: border-box;
  17. padding: 12px 16px 16px 16px;
  18. position: relative;
  19. }
  20. /* 使用伪类选择器凭空产生一个div,挡住上面冒出来的枝枝,
  21. 注意要通过left,和top调整到当好重叠在上面冒出来的枝枝位置才能挡住,也就是要和aside-content中
  22. padding设置左上距离一致才行
  23. */
  24. .aside-content::before {
  25. display: block;
  26. position: absolute;
  27. content: '';
  28. width: 1px;
  29. height: 12px;
  30. background: #fff;
  31. left: 16px;
  32. top: 12px;
  33. }
  34. /* 使用伪类选择器凭空产生一个div,挡住下面冒出来的枝枝,
  35. */
  36. .aside-content::after {
  37. display: block;
  38. position: absolute;
  39. content: '';
  40. width: 1px;
  41. height: 12px;
  42. background: #fff;
  43. left: 16px;
  44. bottom: 16px;
  45. }
  46. .myul {
  47. padding-inline-start: 0px;
  48. margin-block-start: 0px;
  49. margin-block-end: 0px;
  50. padding: 0;
  51. margin: 0;
  52. border-left: 1px dashed #ccccd8;
  53. list-style: none;
  54. }
  55. .myul li {
  56. display: -webkit-box;
  57. display: -ms-flexbox;
  58. display: flex;
  59. -webkit-box-pack: justify;
  60. -ms-flex-pack: justify;
  61. justify-content: space-between;
  62. -webkit-box-align: center;
  63. -ms-flex-align: center;
  64. align-items: center;
  65. margin-bottom: 16px;
  66. }
  67. /* 最后一个li去掉底部的间距 */
  68. .aside-content ul li:nth-last-child(1) {
  69. margin-bottom: 0;
  70. }
  71. .special-column-name {
  72. display: -webkit-box;
  73. display: -ms-flexbox;
  74. display: flex;
  75. -webkit-box-align: center;
  76. -ms-flex-align: center;
  77. align-items: center;
  78. color: #555666;
  79. font-size: 14px;
  80. line-height: 24px;
  81. -webkit-box-flex: 1;
  82. -ms-flex: 1;
  83. flex: 1;
  84. overflow: hidden;
  85. position: relative;
  86. }
  87. /* 利用div实现横着的枝枝效果 */
  88. .special-column-bar {
  89. width: 12px;
  90. height: 1px;
  91. border-bottom: 1px dashed #ccccd8;
  92. -ms-flex-negative: 0;
  93. flex-shrink: 0;
  94. }
  95. </style>
  96. </head>
  97. <body>
  98. <div class="aside-content">
  99. <ul class="myul">
  100. <li><a class="special-column-name">
  101. <div class="special-column-bar"></div>查看视频
  102. </a></li>
  103. <li><a class="special-column-name">
  104. <div class="special-column-bar"></div>资料下载
  105. </a></li>
  106. <li><a class="special-column-name">
  107. <div class="special-column-bar"></div>查看视频
  108. </a></li>
  109. <li><a class="special-column-name">
  110. <div class="special-column-bar"></div>资料下载
  111. </a></li>
  112. <li><a class="special-column-name">
  113. <div class="special-column-bar"></div>查看视频
  114. </a></li>
  115. </ul>
  116. </div>
  117. </body>
  118. </html>

使用vue element ui实现一个这种侧边栏效果

在原来项目里边写,结构就不改了,前面去使用组件循环去生成里边的内容的,情况比较多,我这里简化一下。

里边的组件
默认的里边比较复制要处理各种情况,各种类型的数据显示下载这些,这里简化到非常的简单只显示一下就行了,组件里边就是一个li

  1. <template>
  2. <li>
  3. <a class="special-column-name">
  4. <div class="special-column-bar"></div>实验资料下载哇
  5. </a>
  6. </li>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. }
  13. },
  14. mounted() {
  15. },
  16. // 组件方法
  17. methods: {
  18. }
  19. }
  20. </script>
  21. <style lang="scss" scoped>
  22. .special-column-name {
  23. display: -webkit-box;
  24. display: -ms-flexbox;
  25. display: flex;
  26. -webkit-box-align: center;
  27. -ms-flex-align: center;
  28. align-items: center;
  29. color: #555666;
  30. font-size: 14px;
  31. line-height: 24px;
  32. -webkit-box-flex: 1;
  33. -ms-flex: 1;
  34. flex: 1;
  35. overflow: hidden;
  36. position: relative;
  37. }
  38. /* 利用div实现横着的枝枝效果 */
  39. .special-column-bar {
  40. width: 22px;
  41. height: 1px;
  42. border-bottom: 1px dashed #ccccd8;
  43. -ms-flex-negative: 0;
  44. flex-shrink: 0;
  45. }
  46. </style>

引入组件:

  1. import CourseSourceItemNarrowConcise from './components/lab-course/course-source-item-narrow-concise.vue'
  2. export default {
  3. components: {
  4. CourseSourceItemNarrowConcise,
  5. }
  6. }

引入组件后循环生成:

  1. <el-card class="box-card">
  2. <div slot="header" class="clearfix box-header">
  3. <span class="box-title"><img src="../../assets/imgs/labroom/course-icon.png">实验资料</span>
  4. </div>
  5. <div class="aside-content">
  6. <ul class="labroom_information">
  7. <CourseSourceItemNarrowConcise v-for="(it, sindex) in resources" :r-type="it.recourseType + ''"
  8. :item-data="it" :chapter="chapter" :key="sindex" class="box-item" />
  9. </ul>
  10. </div>
  11. </el-card>

父组件哪里加入样式:

  1. <!-- 实验资料那一块的效果,包含树枝枝 -->
  2. <style lang="scss" scoped>
  3. .aside-content {
  4. max-height: 238px;
  5. overflow: hidden;
  6. -webkit-box-sizing: border-box;
  7. box-sizing: border-box;
  8. padding: 0px 0px 0px 0px;
  9. position: relative;
  10. }
  11. /* 使用伪类选择器凭空产生一个div,挡住上面冒出来的枝枝,
  12. 注意要通过left,和top调整到当好重叠在上面冒出来的枝枝位置才能挡住,也就是要和aside-content中
  13. padding设置左上距离一致才行
  14. */
  15. .aside-content::before {
  16. display: block;
  17. position: absolute;
  18. content: '';
  19. width: 1px;
  20. height: 12px;
  21. background: #fff;
  22. left: 0px;
  23. top: 0px;
  24. }
  25. /* 使用伪类选择器凭空产生一个div,挡住下面冒出来的枝枝,
  26. */
  27. .aside-content::after {
  28. display: block;
  29. position: absolute;
  30. content: '';
  31. width: 1px;
  32. height: 12px;
  33. background: #fff;
  34. left: 0px;
  35. bottom: 0px;
  36. }
  37. .labroom_information {
  38. padding-inline-start: 0px;
  39. margin-block-start: 0px;
  40. margin-block-end: 0px;
  41. padding: 0;
  42. margin: 0;
  43. border-left: 1px dashed #ccccd8;
  44. list-style: none;
  45. }
  46. .labroom_information li {
  47. display: -webkit-box;
  48. display: -ms-flexbox;
  49. display: flex;
  50. -webkit-box-pack: justify;
  51. -ms-flex-pack: justify;
  52. justify-content: space-between;
  53. -webkit-box-align: center;
  54. -ms-flex-align: center;
  55. align-items: center;
  56. margin-bottom: 16px;
  57. }
  58. /* 最后一个li去掉底部的间距 */
  59. .labroom_information li:nth-last-child(1) {
  60. margin-bottom: 0;
  61. }
  62. </style>
增加图标的显示效果

代码如下,只调整组件里边的一点结构和样式就行了,js里边留下的部分处理逻辑的不用管:

  1. <template>
  2. <li>
  3. <a class="special-column-name">
  4. <div class="special-column-bar"></div>
  5. <img :src="require('@/assets/imgs/labroom/' + titleImgs[rType])">
  6. <!-- <span> {{ itemText[rType]['bntText'] }}</span> -->
  7. <span class="describle" :title="itemText[rType]['bntText']+'-'+itemData.name"> {{ itemText[rType]['concise'] }}:{{ itemData.name }}</span>
  8. </a>
  9. </li>
  10. </template>
  11. <script>
  12. import CpProgress from '@/components/cp-progress/cp-progress.vue'
  13. export default {
  14. name: 'CourseSourceItem',
  15. components: {
  16. CpProgress
  17. },
  18. props: {
  19. rType: {
  20. type: String,
  21. default: ''
  22. },
  23. itemData: {
  24. type: Object,
  25. default: () => { }
  26. },
  27. chapter: {
  28. type: Object,
  29. default: () => { }
  30. }
  31. },
  32. data() {
  33. return {
  34. titleImgs: {
  35. '0': 'course-video-1.png',
  36. '1': 'course-video-1.png',
  37. '2': 'rar.png',
  38. '3': 'course-exam-paper.png',
  39. '4': 'course-courseware.png',
  40. '5': 'course-exp.png'
  41. },
  42. itemText: {
  43. '1': {
  44. // bntText: '观看实验视频',
  45. bntText: '观看视频',
  46. concise: "视频",
  47. btnColor: '#3699FF',
  48. lab: '视频'
  49. },
  50. '2': {
  51. // bntText: '素材资料下载',
  52. bntText: '素材下载',
  53. concise: "素材",
  54. btnColor: '#3699FF',
  55. lab: '素材'
  56. },
  57. '3': {
  58. bntText: '试卷下载',
  59. concise: "试卷",
  60. btnColor: '#687DF2',
  61. lab: '试卷'
  62. },
  63. '4': {
  64. // bntText: '课件资料下载',
  65. bntText: '课件下载',
  66. concise: "课件",
  67. btnColor: '#FF6935',
  68. lab: '课件'
  69. },
  70. '5': {
  71. bntText: '进入学习',
  72. concise: "学习",
  73. btnColor: '#3699FF',
  74. lab: ''
  75. }
  76. },
  77. linearColors: [{
  78. v: 100,
  79. s: '#3699FF',
  80. e: '#3699FF'
  81. }]
  82. }
  83. },
  84. mounted() {
  85. console.log(this.itemData)
  86. },
  87. methods: {
  88. btnActon() {
  89. const _self = this
  90. console.log(_self.itemData)
  91. if (_self.rType === '1') { // 看视频
  92. _self.$utils.openwindow(`/#/sublab/watch-the-video/${_self.$route.params.courseid}/${_self.chapter.id}/${_self.itemData.urlID}`, '视频播放')
  93. } else if (_self.rType === '2' || _self.rType === '4' || _self.rType === '3') {
  94. this.$utils.downloadOssFil(_self.itemData.urlID, _self.itemData.name)
  95. // 作业
  96. } else if (_self.rType === '5') { // 查看实验报告
  97. _self.$utils.openwindow(`/#/sublab/learning-lab/${_self.$route.params.courseid}/${_self.chapter.id}/${_self.itemData.labInfo.id}?classid=${this.$route.query.classID}&t=${new Date().getMilliseconds()}`, '实验详情')
  98. }
  99. },
  100. // 下载文件
  101. downLoadFile(id) {
  102. var self = this
  103. self.$http.get('/oss/api/SmartFiles/GetFileUrl', {
  104. fileId: id
  105. }).then(res => {
  106. if (res.success) {
  107. window.location.href = res.data.url
  108. } else {
  109. self.$message({
  110. type: 'error',
  111. message: res.msg
  112. })
  113. }
  114. })
  115. }
  116. }
  117. }
  118. </script>
  119. <style lang="scss" scoped>
  120. .special-column-name {
  121. display: -webkit-box;
  122. display: -ms-flexbox;
  123. display: flex;
  124. -webkit-box-align: center;
  125. -ms-flex-align: center;
  126. align-items: center;
  127. color: #555666;
  128. font-size: 14px;
  129. line-height: 24px;
  130. -webkit-box-flex: 1;
  131. -ms-flex: 1;
  132. flex: 1;
  133. overflow: hidden;
  134. position: relative;
  135. cursor: pointer;
  136. }
  137. /* 利用div实现横着的枝枝效果 */
  138. .special-column-bar {
  139. width: 16px;
  140. height: 1px;
  141. border-bottom: 1px dashed #ccccd8;
  142. -ms-flex-negative: 0;
  143. flex-shrink: 0;
  144. }
  145. .special-column-name img {
  146. width: 24px;
  147. height: 24px;
  148. border: 1px solid #e8e8ed;
  149. border-radius: 2px;
  150. display: block;
  151. margin-right: 8px;
  152. margin-left: 4px;
  153. }
  154. // 内容超出显示省略号
  155. .special-column-name .describle {
  156. overflow: hidden;
  157. text-overflow: ellipsis;
  158. white-space: nowrap;
  159. }
  160. </style>

欢迎加群讨论技术,1群:677373950(满了,可以加,但通过不了),2群:656732739。有需要软件开发,或者学习软件技术的朋友可以和我联系~(Q:815170684)

评价

css弹性盒子,flex布局

css弹性盒子由于版本不同浏览器问题造成了一些不同的写法display:flexbox;在google浏览器中如果使用下面的写法就不行displa...

css图片和文字对齐问题

文字和图片写到一排经常会出现对不齐的问题 这样感觉图片会上来一点没有和文字对齐,如下图 但是如果修改下html结...

css实现简单矩形对话框

在前端做项目时,我们可能会遇到写对话框的需求,这次做视频会议页面就遇到了,记录下日后有个参照。//网页部分 &lt;divcla...

如何修改css中存在的element.style内联样式

改腾讯地图的时候调整了下样式,发现样式一直存在问题,修改style里面的值,一点用都没有,html中这个值还找不到是在哪里出...

珍藏!! JS css不传之秘集合

&lt;!--其中5指每隔5秒刷新一次页面--&gt; &lt;metahttp-equiv=&quot;refresh&quot;content=&quot;5&quot;&gt; =========...

css中单位pxem,rem和vh/vw的理解

&gt;px像素(Pixel)。相对长度单位。像素px是相对于显示器屏幕分辨率而言的。em是相对长度单位。相对于当前对象内文本的字...

DIV+css网页布局常用的一些基础知识整理

一.文件命名规范全局样式:global.css;框架布局:layout.css;字体样式:font.css;链接样式:link.css;打印样式:print...

css相对定位与绝对定位

一般相对定位和绝对定位可以配合起来使用 例如实现如下的效果 只需要在外层div设置为相对定位,在内部设置为绝对定位就...

修改了css后,让浏览器从缓存中更新

当我们修改了css后,如果不做一些操作,浏览器是不会自动更新我们的样式文件的。除非是过期或者用户手动刷新清理缓存等。所...

css定位的简单运用

父容器使用相对定位position: relative子容器使用绝对定位position: relative这样就可以子容器相对父容器定位了,可以写一...

jscss异步加载

有些时候为了效率,我们需要js与css能够异步加载方法1:直接在后面加一个async的关键字&lt;scriptsrc=&quot;~/lib/jquery/d...

css3样式学习代码

上代码!上代码!不说了&lt;!DOCTYPEhtml&gt; &lt;htmllang=&quot;en&quot;&gt; &lt;head&gt; &lt;metacharset=&quot;UT...

css实现动画效果案列:冒泡案列

css实现动画效果案列:冒泡案列效果图:代码:&lt;!DOCTYPEhtml&gt; &lt;html&gt; &lt;head&gt; &lt;metacharset=&quot;...

html/css样式

代码: &lt;!DOCTYPEhtml&gt; &lt;html&gt; &lt;head&gt; &lt;metacharset=&quot;utf-8&quot;/&gt; &lt;title&gt...

css div水平居 。文字垂直居中 。flex的方式实现div的垂直与水平居中。布局模板

DIV等元素水平居中定宽度+margin:top auto可以让一个块级别元素在外层居中例如这样:效果:可以看到这个div已经居中了但是...

使用jquery操作元素的css样式(获取、修改等等)

使用jquery操作元素的css样式(获取、修改等等) //1、获取和设置样式 $(&quot;#tow&quot;).attr(&quot;class&quot;)...