<html>

<head>
    <style type="text/css">
        div:before {
            content: url(open_live.png);
            background-color: #ff0000;
            width: 100px;
            height: 100px;
        }
        
        div::after {
            content: url(open_live.png);
            background-color: #ff0000;
        }
        
        p:before {
            content: "before-";
        }
        
        p::after {
            content: "-after";
        }
        
        button:before {
            content: "before-";
        }
        
        button::after {
            content: "-after";
        }
    </style>
</head>

<body>
    <p style=" background-color: #ff0000;">111111111111111</p>
    <div class="container">
        <p>222222222222222</p>
        <button>ssss</button>
    </div>

</html>

效果:

有关css伪元素before after

通过效果我们可以看出,如果是文本内,添加文字的话是直接在标签的前面或后面添加文字

如果是块,则在该块的开始或者结束位置添加子元素。

另外注意如果是在p标签前面添加img这个是没有效果的

但如果是在div标签前面添加文本 :

<html>

<head>
    <style type="text/css">
        div:before {
            content: "before";
            background-color: #ff0000;
            width: 100px;
            height: 100px;
        }
        
        div::after {
            content: "after-";
            background-color: #ff0000;
        }
    </style>
</head>

<body>

    <div class="container" style=" background-color: #00ff00;">
        <p>222222222222222</p>
        <button>ssss</button>
    </div>

</html>

效果如下

有关css伪元素before after

相关文章:

  • 2022-02-02
  • 2022-12-23
  • 2021-11-07
  • 2021-06-04
  • 2021-04-03
  • 2021-07-11
猜你喜欢
  • 2021-10-24
  • 2021-07-16
  • 2021-08-09
  • 2021-06-05
  • 2021-11-04
  • 2021-08-06
  • 2021-12-07
相关资源
相似解决方案