001偽元素絕對定位相對於本身元素的位置


一、效果

本身元素width:100px,絕對定位后:left:50px,如下圖所示.

 

 

二、代碼如下:

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{padding: 0;margin: 0;}
        .test {
            width: 100px;
            height: 100px;
            background: green;
        }

        .test:after {
            position: absolute;
            left: 50px;
            content: "12";
            background: grey;
            width: 50px;
            height: 50px;
        }
    </style>
</head>
<body>
    <div class='test'></div>
</body>
</html>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM