【CSS进阶】巧用伪元素before和after制作绚丽效果(中)

简介: 【CSS进阶】巧用伪元素before和after制作绚丽效果

【CSS进阶】巧用伪元素before和after制作绚丽效果(上):https://developer.aliyun.com/article/1483392


6 绚丽流动边框

image.png

image.png

<div class="box-line1"></div>
.box-line2,
.box-line2::before,
.box-line2::after {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
}

.box-line2 {
  width: 200px;
  height: 200px;
  margin: auto;
  color: #69ca62;
  box-shadow: inset 0 0 0 1px rgba(105, 202, 98, 0.5);
}

.box-line2::before,
.box-line2::after {
  content: "";
  z-index: 99;
  margin: -5%;
  box-shadow: inset 0 0 0 2px;
  animation: clipMe 8s linear infinite;
}

.box-line2::before {
  animation-delay: -4s;
}

.box-line2:hover::after,
.box-line2:hover::before {
  background-color: rgba(255, 0, 0, 0.3);
}

@keyframes clipMe {

  0%,
  100% {
    clip: rect(0px, 220px, 2px, 0px);
  }

  25% {
    clip: rect(0px, 2px, 220px, 0px);
  }

  50% {
    clip: rect(218px, 220px, 220px, 0px);
  }

  75% {
    clip: rect(0px, 220px, 220px, 218px);
  }
}

@keyframes surround {

  0%,
  100% {
    clip: rect(0px, 220px, 2px, 0px);
  }

  25% {
    clip: rect(0px, 2px, 220px, 0px);
  }

  50% {
    clip: rect(218px, 220px, 220px, 0px);
  }

  75% {
    clip: rect(0px, 220px, 220px, 218px);
  }
}

.box-line1:before,
.box-line1:after {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  content: "";
  z-index: 99;
  margin: -5%;
  animation: surround linear infinite 8s;
  box-shadow: inset 0 0 0 2px #69ca62;
}

.box-line1:before {
  animation-delay: -4s;
}

.box-line1 {
  border: 1px solid #69ca62;
  position: absolute;
  left: 500px;
  top: 200px;
  margin: auto;
  width: 200px;
  height: 200px;
  margin: auto;
}

7.Tooltip提示

image.png

<div class="tip" data-tip="CSS伪类">CSS伪类</div>
.tip::after {
  content: attr(data-tip);
  display: none;
  position: absolute;
  padding: 5px 10px;
  left: 15%;
  bottom: 100%;
  width: 150px;
  margin-bottom: 12px;
  transform: translateX(-50%);
  font-size: 12px;
  background: #000;
  color: #fff;
  cursor: default;
  border-radius: 4px;
}

.tip::before {
  content: " ";
  position: absolute;
  display: none;
  left: 15%;
  bottom: 100%;
  transform: translateX(-50%);
  margin-bottom: 3px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 9px solid #000;
}

.tip:hover::after,
.tip:hover::before {
  display: block;
}

8.CSS 伪类盒子阴影


使用伪元素:before and :after制作出了完美惊艳的相片阴影效果。其中的技巧是使用绝对定位固定伪元素,然后给它们的z-index一个负值,以背景出现。

image.png

image.png

<div class="box effect2">
  <h3>CSS 伪类盒子阴影</h3>
</div>
.effect2 {
    position: relative;
}

.effect2::before, .effect2::after {
    z-index: -1;
    position: absolute;
    content: "";
    bottom: 15px;
    left: 10px;
    width: 50%;
    top: 80%;
    max-width: 300px;
    background: #777;
    -webkit-box-shadow: 0 15px 10px #777;
    -moz-box-shadow: 0 15px 10px #777;
    box-shadow: 0 15px 10px #777;
    -webkit-transform: rotate(-3deg);
    -moz-transform: rotate(-3deg);
    -o-transform: rotate(-3deg);
    -ms-transform: rotate(-3deg);
    transform: rotate(-3deg);
}
.effect2::after {
    -webkit-transform: rotate(3deg);
    -moz-transform: rotate(3deg);
    -o-transform: rotate(3deg);
    -ms-transform: rotate(3deg);
    transform: rotate(3deg);
    right: 10px;
    left: auto;
}

9.Tabs当前激活状态

image.png

    <div class="sm-box flex">
        <div class="menu-tabs active">首页</div>
        <div class="menu-tabs">新闻</div>
        <div class="menu-tabs">视频</div>
        <div class="menu-tabs">图片</div>
    </div>
.menu-tabs {
  display: block;
  padding: 0.25rem 1.5rem;
  clear: both;
  font-weight: 400;
  color: #212529;
  text-align: inherit;
  white-space: nowrap;
  background-color: transparent;
  width: 50px;
  border: 0;
  height: 35px;
  justify-content: center;
  display: flex;
  cursor: pointer;
}

.menu-tabs:hover {
  color: #20a884;
  position: relative;
}

.menu-tabs:hover:after {
  position: absolute;
  content: "";
  border: 1px solid #20a884;
  width: 3rem;
  left: 0;
  bottom: 0;
  margin-left: 50%;
  transform: translateX(-50%);
}

.active {
  position: relative;
  color: #20a884;
}

.flex {
  display: flex;
}

.active::after {
  position: absolute;
  content: "";
  border: 1px solid #20a884;
  width: 3rem;
  left: 0;
  bottom: 0;
  margin-left: 50%;
  transform: translateX(-50%);
}

10.伪元素模糊背景

image.png

<div class="container">
   <div class="overlay">
      <h1>A blurred overlay</h1>
     <p>... mask or whatever
     <br>that is responsive and could be cross-browser compatible back to IE9</p>
   </div>
</div>
.container {
  width: 100%;
  height: 100%;
  margin: 0;
}

.container,
.overlay:before {
  background: url(https://wow.techbrood.com/assets/landing.jpg) no-repeat fixed 0 0 / cover;
}

.container {
  -webkit-box-align: center;
  -webkit-align-items: center;
  -ms-flex-align: center;
  align-items: center;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  -ms-flex-pack: center;
  justify-content: center;
}

.overlay {
  max-height: 200px;
  margin: 0 auto;
  max-width: 768px;
  padding: 50px;
  position: relative;
  color: white;
  font-family: "Lato";
  position: relative;
  text-align: center;
  z-index: 0;
}

.overlay:before {
  content: "";
  -webkit-filter: blur(100px);
  filter: blur(100px);
  height: 100%;
  left: 0;
  position: absolute;
  top: 0;
  width: 100%;
  z-index: -1;
}

11.蓝湖文字

image.png

<span class="lanhu_text">
   本站由叫我詹躲躲提供技术支持
</span>
.lanhu_text {
  position: relative;
  color: #2878ff;
}

.lanhu_text::before {
  content: "";
  width: 80px;
  height: 20px;
  position: absolute;
  left: -86px;
  top: 0;
  background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAAABCAYAAABJwyn/AAAAjElEQVQoU22NSw7CQAxDX8ahICF2HIDTcf9d1c8kaDpthQSL6CmxHRuk8cZfMxqf6DGh+Y5uCxquaB7xdUCXilZHWvBorEiOaqAKrkRRUEmUOw283TKRRb9b4GnIEpWmGYrA237kDh1w6J5N7zzzZv13gtuvT7t++jefUTYmwvpk7v3fPaCzn//9LfsBvRpHnliu+xMAAAAASUVORK5CYII=) 0 no-repeat;
}

.lanhu_text::after {
  content: "";
  width: 80px;
  height: 20px;
  position: absolute;
  right: -86px;
  top: 0;
  background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAAABCAYAAABJwyn/AAAAhElEQVQoU22OSw7CQAxDXzJDWbHiEFyRJQflFggJSjyDph9oC6snx45lO52rrKJqzIyNlkFUPv6vnv+3uW9vrPpBq77/uWFPAXnrnfYVQ16JiWq0stjvxKB9vDc/MeaXWo5cqDEFUkKpEuEoB3ollHvUZ9QV4rFD3R3d9ujwJK5HxAW9AStemAIOwCNlAAAAAElFTkSuQmCC) 100% no-repeat;
}

【CSS进阶】巧用伪元素before和after制作绚丽效果(下):https://developer.aliyun.com/article/1483395

相关文章
|
存储 SQL 关系型数据库
PostgreSQL系统字段cmin和cmax详解
1.cmin和cmax是什么 PG中每个表都包含了一些系统字段,其中包括cmin和cmax。 cmin:插入该元组的命令在插入事务中的命令标识(从0开始累加) cmax:删除该元组的命令在插入事务中的命令标识(从0开始累加) 可以在Select命令的输出列表中显式地指定系统字段。
3816 0
|
10月前
|
供应链 数据可视化 BI
多平台数据整合工具新趋势:支持API实时联动的看板方案
在电商运营中,数据分散在多个平台导致效率低下、决策滞后。数据整合看板工具通过聚合多源数据,实现可视化、实时同步与低门槛操作,帮助团队高效利用数据,提升运营效率与决策质量。
|
10月前
|
SQL 关系型数据库 MySQL
四、Sqoop 导入表数据子集
在实际数据导入场景中,我们经常只需要数据库中的一部分数据,比如按条件筛选的行、特定的几列。这篇文章详细讲解了如何使用 Sqoop 的 --where、--columns、--query 等方式灵活实现子集导入,配有完整示例和注意事项,助你更精准地控制数据流向 HDFS 或 Hive。
330 1
|
10月前
|
人工智能 机器人 Serverless
安诺机器人 X 阿里云函数计算 AI 咖啡印花解决方案
当云计算遇见具身智能,AI咖啡开启零售新体验。用户通过手机生成个性化图像,云端AI快速渲染,机器人精准复刻于咖啡奶泡之上,90秒内完成一杯可饮用的艺术品。该方案融合阿里云FunctionAI生图能力与安诺机器人高精度执行系统,实现AIGC创意到实体呈现的闭环,为线下零售提供低成本、高互动、易部署的智能化升级路径,已在商场、机场、展馆等场景落地应用。
安诺机器人 X 阿里云函数计算 AI 咖啡印花解决方案
|
10月前
|
缓存 监控 供应链
亚马逊 MWS API 实战:商品详情精准获取与跨境电商数据整合方案
本文详细解析亚马逊MWS API接口的技术实现,重点解决跨境商品数据获取中的核心问题。文章首先介绍MWS接口体系的特点,包括多站点数据获取、AWS签名认证等关键环节,并对比普通电商接口的差异。随后深入拆解API调用全流程,提供签名工具类、多站点客户端等可复用代码。针对跨境业务场景,文章还给出数据整合工具实现方案,支持缓存、批量处理等功能。最后通过实战示例展示多站点商品对比和批量选品分析的应用,并附常见问题解决方案。该技术方案可直接应用于跨境选品、价格监控等业务场景,帮助开发者高效获取亚马逊商品数据。
|
前端开发 JavaScript
探讨JavaScript实现类似弹幕的跑马灯效果
探讨JavaScript实现类似弹幕的跑马灯效果
1463 1
|
设计模式 负载均衡 监控
探索微服务架构下的API网关设计
在微服务的大潮中,API网关如同一座桥梁,连接着服务的提供者与消费者。本文将深入探讨API网关的核心功能、设计原则及实现策略,旨在为读者揭示如何构建一个高效、可靠的API网关。通过分析API网关在微服务架构中的作用和挑战,我们将了解到,一个优秀的API网关不仅要处理服务路由、负载均衡、认证授权等基础问题,还需考虑如何提升系统的可扩展性、安全性和可维护性。文章最后将提供实用的代码示例,帮助读者更好地理解和应用API网关的设计概念。
426 8
|
人工智能 编解码 安全
全球AI新浪潮:智能媒体服务的技术创新与AIGC加速出海
本文介绍了智能媒体服务的国际化产品技术创新及AIGC驱动的内容出海技术实践。首先,探讨了媒体服务在视频应用中的升级引擎作用,分析了国际市场的差异与挑战,并提出模块化产品方案以满足不同需求。其次,重点介绍了AIGC技术如何推动媒体服务2.0智能化进化,涵盖多模态内容理解、智能生产制作、音视频处理等方面。最后,发布了阿里云智能媒体服务的国际产品矩阵,包括媒体打包、转码、实时处理和传输服务,支持多种广告规格和效果追踪分析,助力全球企业进行视频化创新。
740 0
|
机器学习/深度学习 自然语言处理 并行计算
|
人工智能 关系型数据库 分布式数据库
用友X阿里云:加速AI in SaaS
在今年的云栖大会上,用友公司与阿里云共同宣布将进一步加深合作,推动用友BIP与阿里云深度融合,以SaaS模式为诸多大中型企业客户提供一体化解决方案。同时,通义大模型已作为底层基础大模型集成到用友企业服务大模型YonGPT,加速企业数智化转型。
621 7