如何给背景图片加颜色遮罩

今天药忘吃喽~ 2022-01-13 10:25 437阅读 0赞

方法一:通过定位叠加(注意层级关系)

  1. <style>
  2. .block {
  3. position: relative;
  4. margin: 50px auto;
  5. width: 700px;
  6. height: 450px;
  7. }
  8. .block > img {
  9. position: absolute;
  10. width: 100%;
  11. height: 100%;
  12. }
  13. .block > div {
  14. position: absolute;
  15. z-index: 2;
  16. width: 100%;
  17. height: 100%;
  18. background-color: rgba(8, 8, 8, 0.31);
  19. }
  20. </style>
  21. <div class="block">
  22. <img src="../小米/img/1.jpg" alt=""/>
  23. <div></div>
  24. </div>

方法二:通过伪类元素叠加

  1. <style>
  2. *{
  3. width: 100%;
  4. height: 100%;
  5. }
  6. .block{
  7. position: relative;
  8. margin: 50px auto;
  9. width: 700px;
  10. height: 450px;
  11. }
  12. .block > img {
  13. position: absolute;
  14. width: 100%;
  15. height: 100%;
  16. }
  17. .block>div:before{
  18. content: "";
  19. position: absolute;
  20. left: 0;
  21. right: 0;
  22. bottom: 0;
  23. top: 0;
  24. background-color: rgba(204, 152, 22, 0.36);
  25. z-index: 2;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div class="block">
  31. <img src="../小米/img/1.jpg" alt=""/>
  32. <div></div>
  33. </div>

方法三 正片叠底

  1. <style>
  2. *{
  3. width: 0;
  4. height: 0;
  5. }
  6. .block {
  7. position: relative;
  8. margin: 50px auto;
  9. width: 700px;
  10. height: 450px;
  11. }
  12. .block > img {
  13. position: absolute;
  14. width: 100%;
  15. height: 100%;
  16. }
  17. .block > div {
  18. position: absolute;
  19. z-index: 2;
  20. width: 100%;
  21. height: 100%;
  22. background-color: rgba(141, 255, 236, 0.31);
  23. background-blend-mode: multiply;/*正片叠底*/
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div class="block">
  29. <img src="../小米/img/1.jpg" alt=""/>
  30. <div></div>
  31. </div>

方法四 背景模糊加颜色叠加

  1. <style>
  2. .block {
  3. position: relative;
  4. margin: 50px auto;
  5. width: 700px;
  6. height: 450px;
  7. }
  8. .block > img {
  9. position: absolute;
  10. width: 100%;
  11. height: 100%;
  12. }
  13. .block > div {
  14. position: absolute;
  15. z-index: 2;
  16. width: 100%;
  17. height: 100%;
  18. background-color: rgba(255, 161, 80, 0.31);
  19. background-blend-mode: multiply;
  20. filter: blur(2px);
  21. overflow: hidden;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <body>
  27. <div class="block">
  28. <img src="../小米/img/1.jpg" alt=""/>
  29. <div></div>
  30. </div>

发表评论

表情:
评论列表 (有 0 条评论,437人围观)

还没有评论,来说两句吧...

相关阅读

    相关 图片效果

    欢迎访问我的博客地址 : [博客地址][Link 1] **鼠标移入容器半遮罩层从下方逐渐移上去** 话不多说,直接上代码! <!DOCTYPE html...