首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[分享]css3各种折角效果

发布于 2024-11-11 14:23:49
0
45

CSS3中有很多种能够实现折角效果的样式属性,以下我们来一一介绍:

/* 第一种方式:使用 border 属性 */

.box1 {
  width: 100px;
  height: 100px;
  border-top: 50px solid #f00;
  border-right: 50px solid #f00;
}

/* 第二种方式:使用 transform 属性 */

.box2 {
  width: 100px;
  height: 100px;
  transform: skew(45deg);
}

.box2::before {
  content: ';
  display: block;
  width: 100%;
  height: 100%;
  background: #f00;
  transform: skew(-45deg) translateX(-50%);
}

/* 第三种方式:使用 clip-path 属性 */

.box3 {
  width: 150px;
  height: 150px;
  clip-path: polygon(50% 0, 100% 50%, 50% 99%, 0 50%);
  background: #f00;
}

/* 第四种方式:使用 border-radius 属性 */

.box4 {
  width: 100px;
  height: 100px;
  border-radius: 50% / 100%;
  background: #f00;
}

/* 第五种方式:使用伪类和 transform 属性 */

.box5 {
  width: 100px;
  height: 100px;
  position: relative;
  overflow: hidden;
}

.box5::before {
  content: ';
  position: absolute;
  top: -50%;
  right: -50%;
  bottom: -50%;
  left: -50%;
  transform: rotate(45deg);
  background: #f00;
} 

以上就是 CSS3 中实现折角效果的各种方式,可以根据具体需求选择合适的方式进行实现。

评论
一个月内的热帖推荐
91云脑
Lv.1普通用户

62849

帖子

14

小组

291

积分

赞助商广告
站长交流