html怎样给背景图片加遮罩

 时间:2026-04-22 18:22:22

1、首先,给大家说一下给图片加背景色的两种方法:因为一个div同时设置background-color和background-image的话,color是处于img层下方的,所以需要再创建一个div作为他的子div,然后设置子div的背景颜色,

html怎样给背景图片加遮罩

2、代码如下:css: .wrap{    position: relative;    height: 700px;    background: url(i/pic4.jpg) no-repeat;    -webkit-background-size: 100%。

html怎样给背景图片加遮罩

3、  background-size: 100%;}.inner{    height: 700px;    background: rgba(0,0,0,.4);}html: <div class="wrap">    <div class="inner"></div> </div>。

html怎样给背景图片加遮罩

4、通过after伪元素设置,代码如下:wrap{    position: relative;    height: 700px;    background: url(i/pic4.jpg) no-repeat。

html怎样给背景图片加遮罩

5、 -webkit-background-size: 100%;    background-size: 100%;}.wrap:after{    position: absolute;    top: 0;    left: 0;    content: "";    background-color: yellow;    opacity: 0.2;    z-index: 1;    width: 100%;    height: 100%;}这两种方法实现的效果都是一样的。

html怎样给背景图片加遮罩

  • 制作网页时如何让导航栏始终保持在顶端
  • 如何在HTML中插入图片
  • html图片大小怎么设置
  • 怎样让html中的文字垂直水平居中显示
  • 在html里面怎么让文字居中显示?
  • 热门搜索
    红烧鱼的做法和步骤 怎么减肥肚子 球蛋白低是怎么回事 延禧攻略番外篇 奥利司他胶囊减肥效果怎样 长白山天池旅游攻略 苹果的id怎么注册 教育经历怎么填 公主恋人攻略 赛乐赛奥利司他胶囊减肥效果怎样