分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

纯css实现气泡效果

发布时间:2023-09-06 02:18责任编辑:胡小海关键词:暂无标签
先上代码:
div.bubble{ ?position: absolute; ?margin: 0; ?padding: 0; ?color: #86181d; ?background-color: #ffdce0; ?border-color: #cea0a5; ?display:block; ?border:1px solid; ?border-radius: 4px; ?padding: 2px;}div.bubble::before{ ?content: ‘ ‘; ?display: block; ?border-right:7px solid #ffdce0; ?border-left:7px solid ?transparent; ?border-top:7px solid ?transparent; ?border-bottom: 7px solid transparent; ?width: 0px; ?height: 0px; ?position: absolute; ?top:4px; ?left:-14px; ?z-index: 3;}div.bubble::after{ ?content: ‘ ‘; ?display: block; ?border-right:8px solid #86181d; ?border-left:8px solid ?transparent; ?border-top:8px solid ?transparent; ?border-bottom: 8px solid transparent; ?width: 0px; ?height: 0px; ?position: absolute; ?top:3px; ?left:-16.5px; ?z-index: 2;}

效果图:

 主要运用的是1.border 组成的直角三角形。2,before 和 after 伪元素 。3,z-index属性

1. 将元素的长宽设置为0,并且将border的3条边设置为透明的,就会出现border颜色的直角三角形;

2. 利用伪元素after和before,可以不用另外创建子元素,这可以避免不必要的dom复杂性

3. 用两个border设置的三角形,一大一小,可以模拟边框的效果

纯css实现气泡效果

原文地址:https://www.cnblogs.com/incredible-x/p/9807212.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved