CSS3_伪类选择器

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>伪元素字体图标</title>
    <style>
        @font-face {
            font-family: 'icomoon';
            src: url('fonts/icomoon.eot?c5w3jh');
            src: url('fonts/icomoon.eot?c5w3jh#iefix') format('embedded-opentype'), url('fonts/icomoon.ttf?c5w3jh') format('truetype'), url('fonts/icomoon.woff?c5w3jh') format('woff'), url('fonts/icomoon.svg?c5w3jh#icomoon') format('svg');
            font-weight: normal;
            font-style: normal;
            font-display: block;
        }
        
        span {
            font-family: "icomoon";
            position: absolute;
            top: 6px;
            right: 8px;
        }
        
        div,
        p {
            position: relative;
            width: 150px;
            height: 30px;
            border: 1px solid #000;
        }
        /* P::after {
            content: '';
            font-family: "icomoon";
            position: absolute;
            top: 6px;
            right: 8px;
        } */
        
        P::after {
            content: '\ea50';
            font-family: "icomoon";
            position: absolute;
            top: 6px;
            right: 8px;
        }
    </style>
</head>

<body>
    <div>
        <span></span>
    </div>
    <!-- 用伪元素选择器 -->
    <p></p>
</body>

</html>
<!-- 回忆:
早先作图标icomoon的步骤:
1.设置一个div并在div中设置一个span标签用于放图标
2.打开https://icomoon.io/app/#/select,选择标签
3.保存下载的标签并解压。找到demo.html页面复制要用的标签
4.将标签放到span之中。并赋值icomoon中第一段代码。
5.将5中复制代码放到style中,并给span标签定位
6.根据子绝父相,给div定位
对比
用伪元素选择器的优点是不用其他盒子承载图标,因为为类选择器就相当于是盒子 -->
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值