美文网首页
css3-伪元素before,after

css3-伪元素before,after

作者: AssertDo | 来源:发表于2019-08-26 13:30 被阅读0次
<!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>

相关文章

网友评论

      本文标题:css3-伪元素before,after

      本文链接:https://www.haomeiwen.com/subject/iamrectx.html