网站首页 > 知识剖析 正文
前言
常见的聊天对话框,如微信,都是由一个长方形加一个三角形组合而成,重点就在于三角形的制作
一、css制作三角形的实现原理?
三角形的实现原理是元素宽高设置为0,再设置边框宽度、样式和颜色。
例如:
二、单个三角形
1.原理
只设置一条边的颜色,其他三边颜色设置为透明
例如:
- 向下三角
- 向右三角
- 向上三角
- 向左三角
2.空心三角形
只能看见边线,内部透明的三角形该如何用css实现呢
实现思路:使用css伪元素定位,用两个不同颜色、不同大小的实心三角形叠加,以达到“空心”的效果
<div class="box"><div>
<style>
.box {
width: 200px;
height: 50px;
background-color: #fff;
border-radius: 6px;
position: relative;
border: 1px solid red;
}
.box::before{
position: absolute;
top: 15px;
left: 200px;
content: '';
border-width: 10px;
border-style: solid;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: red;
}
.box::after {
position: absolute;
top: 15px;
left: 198.5px;
content: '';
border-width: 10px;
border-style: solid;
border-top-color: transparent;
border-right-color: transparent;
border-bottom-color: transparent;
border-left-color: #fff;
}
</style>
- 上一篇: CSS margin就像是网页中控制元素周围间距的“空气”
- 下一篇: 你知道空白网页的颜色是什么吗?
猜你喜欢
- 2024-11-19 CSS中的混合模式,制作高级特效的必备技巧
- 2024-11-19 19.HTML CSS边距、边框、填充和内容
- 2024-11-19 使用CSS实现图片的磨砂玻璃效果
- 2024-11-19 CSS 盒子模型详解
- 2024-11-19 CSS前端笔记-第二天
- 2024-11-19 38个不可错过的实用前端工具
- 2024-11-19 深入浅出超好用的 CSS 阴影技巧
- 2024-11-19 分享几个css实用技巧
- 2024-11-19 前端入门——css颜色和背景
- 2024-11-19 学前端怎能不知css系列-css初识02
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)