html 的css骚操作,意想不到的 CSS 伪元素 before/after 各种骚操作 - 文章教程

CSS 伪元素 before/after 我们经常用到,常见的就是画个三角形、绘画背景阴影等,这篇文章将给大家分享还有很多有趣的操作,比如画线画图标等。

画细线

普通的 border 最小高度为1px,用伪元素+transform 属性可以画出小于 1px 的细线

.thin-line {

height: 40px;

line-height: 40px;

position: relative;

border-top: 1px solid #ff4891;

}

.thin-line:after {

content: "";

height: 1px;

position: absolute;

left: 0;

bottom: 0;

right: 0;

top: auto;

background-color: #ff4891;

display: block;

-webkit-transform-origin: 100% 0;

transform-origin: 100% 0;

-webkit-transform: scaleY(0.3);

transform: scaleY(0.3);

}

上为1px的线,下为利用伪元素绘制的0.3px的细线

效果如下:

758cebe3e570f82d8d01b46f0bc78e18.png

画图形

.mt-20 {

margin-top: 20px;

}

.title {

padding: 0 30px;

position: relative;

}

.circle:before {

content: "";

width: 12px;

height: 12px;

display: block;

border-radius: 50%;

position: absolute;

left: 0;

top: 50%;

transform: translateY(-50%);

background-color: #ff4891;

}

.rhombus:before {

content: "";

width: 10px;

height: 10px;

display: block;

position: absolute;

left: 0;

top: 50%;

transform: translateY(-50%) rotate(45deg);

background-color: #ff4891;

}

.triangle:before {

content: "";

width: 0;

height: 0;

display: block;

position: absolute;

left: 0;

top: 50%;

transform: translateY(-50%);

border-left: 10px solid #ff4891;

border-top: 10px solid transparent;

border-right: none;

border-bottom: 10px solid transparent;

}

.parallelogram:before {

content: "";

width: 12px;

height: 10px;

display: block;

position: absolute;

left: 0;

top: 50%;

transform: translateY(-50%) skew(-30deg);

background-color: #ff4891;

}

.isoscelesTrapezoid:before {

content: "";

width: 12px;

height: 10px;

display: block;

position: absolute;

left: 0;

top: 50%;

transform: translateY(-50%) perspective(1px) rotateX(3deg);

background-color: #ff4891;

}

.star-six:before {

content: "";

width: 0;

height: 0;

border-left: 8px solid transparent;

border-right: 8px solid transparent;

border-bottom: 16px solid #ff4891;

position: absolute;

left: 0;

top: 50%;

transform: translateY(-50%);

}

.star-six:after {

width: 0;

height: 0;

border-left: 8px solid transparent;

border-right: 8px solid transparent;

border-top: 16px solid #ff4891;

content: "";

position: absolute;

left: 0;

top: calc(50% + 6px);

transform: translateY(-50%);

}

.arrow-right:after {

content: "";

display: inline-block;

height: 10px;

width: 10px;

border-width: 2px 2px 0 0;

border-color: #ff4891;

border-style: solid;

transform: matrix(0.71, 0.71, -0.71, 0.71, 0, 0) translateY(-50%);

position: absolute;

top: 50%;

left: 0;

}

菱形
圆形
三角形
平行四边形
等腰梯形
六角星

效果如下:

8ee5cc387d2cefbe739945255f5f5517.png

特殊字符

.book,

.step {

display: inline-block;

position: relative;

}

.book::before {

content: "《";

left: -10px;

}

.book::after {

content: "》";

right: -10px;

}

.step::before {

content: "1";

left: 0;

width: 20px;

height: 20px;

line-height: 20px;

border-radius: 50%;

display: inline-block;

background: #000;

color: #ffffff;

text-align: center;

margin-right: 8px;

}

.sun::before {

content: "\2600";

font-size: 16px;

}

.phoneNumber::before {

content: "\260E";

font-size: 16px;

}

大秦帝国
步骤一
太阳
18945645654

效果如下:

323204b7c4686d0bac79572ac2953703.png

画图标

781eda1061c812fa5fe2bcbd052f96a7.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值