首页 编程语言 css

使用CSS的mask属性实现头像与国旗的融合

效果图:

  • 所有代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .pic {
        position: relative;
        margin: auto;
        width: 200px;
        height: 200px;

        /* 头像 */
        background: url("pic.jpg") no-repeat;
        background-size: cover;
      }

      .pic::before {
        content: "";
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        right: 0;

        /* 国旗的图片 */
        background: url("china.png") no-repeat;
        background-size: cover;
        
        /* 遮罩层 */
        -webkit-mask: linear-gradient(110deg, white 10%, transparent 70%, transparent);
      }
    </style>
  </head>
  <body>
    <div class="pic"></div>
  </body>
</html>
相关推荐