欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 旅游 > CSS——伪元素:before

CSS——伪元素:before

2024/10/24 15:24:11 来源:https://blog.csdn.net/qq_43730272/article/details/141158091  浏览:    关键词:CSS——伪元素:before

CSS——伪元素&:before

简单介绍:

::after和::before的使用很简单,可以认为其所在元素上存在一前一后的两个的元素,这两个元素默认是内联元素,但我们可以为其增添样式。::after和::before使用的时候一定要注意,必须设置content,否则这两个伪元素是无法显示出来的。而content属性,会作为这两个伪元素的内容嵌入他们中。

<style>p:before{content: "1";p:after{content: "3";}</style><p>2</p>
使用示例:

&:before竖条

<header class="header">日志</header><el-timeline><el-timeline-item v-for="(activity, index) in activities" :key="index" :timestamp="activity.timestamp">{{ activity.content }}</el-timeline-item></el-timeline>
const activities = [{content: 'Event start',timestamp: '2018-04-15'},{content: 'Approved',timestamp: '2018-04-13'},{content: 'Success',timestamp: '2018-04-11'}]
<style scoped lang="scss">.header {position: relative;padding-left: 10px;font-weight: 800;font-size: 16px;margin-bottom: 20px;&:before {content: '';display: block;width: 4px;height: 20px;background: #1890ff;border-radius: 2px;position: absolute;left: 0;top: 50%;transform: translateY(-50%);}}
</style>

实现效果:
在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com