
CSS
CSSimg { width: 300px; height: 300px;}img::before { content: ""; position: ABSolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 100%; height: 100%; background-color: red;}img::after { content: ""; position: ABSolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 100%; height: 100%; background-color: blue;}img::both { display: contents;}在上面的代码中,我们为一个元素添加了两个伪元素:before和after。这两个伪元素用于创建一个红色和蓝色的遮罩,并使用display: contents属性来显示所有内容。你也可以根据需要调整遮罩的颜色、大小等属性来获得不同效果。注意:由于mask属性目前还不支持在IE11及以下浏览器中使用,因此需要适配这些浏览器。Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号