马不停蹄 发表于 2023-6-26 18:39:16

css伪对象before,after,content

css伪对象before,after,content

概念:就是给元素追加一个虚拟标签,由css加载,可以节省html的资源开销,必须有content属性,默认是行元素,可以进行转换。::after:在指定的标签后面添加一个对象::before:在指定的标签前面添加一个对象content:元素里面的内容(内容中不能写标签)代码如下:<style type="text/css">
                .box{width:200px;background:#f00;height:300px;}
                .box::before{
                        content:'开头的内容';height:100px;
                        line-height:100px;color:#fff;background:#00f;
                }
                .box::after{
                        content:'这是一个段落';
                        background-color:green;
                        display:block;height:50px;
                }
        </style>
</head>
<body>
        <div class="box"></div>
</body>
页: [1]
查看完整版本: css伪对象before,after,content