css3-伪元素before,after

2019-08-26  本文已影响0人  AssertDo
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>伪元素:::before  ::after</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        body{
            padding: 200px;
        }
        div:nth-of-type(1){
            width: 300px;
            height: 200px;
            background-color: red;
            float: left;
        }
        div:nth-of-type(2){
            width: 100px;
            height: 200px;
            background-color: blue;
            float: left;
            position: relative;
        }

        div:nth-of-type(2)::before{
            /*必须添加content属性,否则后期不可见*/
            content: "";
            /*默认是行级元素,如果想设置宽高,就必须转换为块级元素*/
            position: absolute;
            width: 20px;
            height: 20px;
            background-color: #fff;
            border-radius: 10px;
            left: -10px;
            top: -10px;
        }
        div:nth-of-type(2)::after{
            /*必须添加content属性,否则后期不可见*/
            content: "";
            /*默认是行级元素,如果想设置宽高,就必须转换为块级元素*/
            position: absolute;
            width: 20px;
            height: 20px;
            background-color: #fff;
            border-radius: 10px;
            left: -10px;
            bottom: -10px;
        }
    </style>
</head>
<body>
<div></div>
<div></div>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读