1

我正在尝试使用此代码在背景图像上放置渐变

background: url('../img/newspaper.jpeg'),linear-gradient(to bottom right,#002f4b, #dc4225);
background-size: cover;

我正在获取图像,但未应用渐变

4

2 回答 2

5

先添加渐变,再添加图片url,就像这样:

background: linear-gradient(rgba(244, 67, 54, 0.95),
                            rgba(33, 150, 243, 0.75),
                            rgba(139, 195, 74, 0.75),
                            rgba(255, 87, 34, 0.95)),
                            url("http://placehold.it/200x200");

或者看看下面的片段:

.bg {
  background: linear-gradient(
    rgba(244, 67, 54, 0.45),
    rgba(33, 150, 243, 0.25),
    rgba(139, 195, 74, 0.25),
    rgba(255, 87, 34, 0.45)),
    url("http://placehold.it/200x200");
  width: 200px;
  height: 200px;
}
<div class="bg"></div>

希望这可以帮助!

于 2016-11-06T03:44:45.580 回答
0

div {
  width: 350px;
  height: 350px;
  background: linear-gradient(to bottom right, rgba(0,47,75,.9), rgba(220,66,37,.9)), url(http://placehold.it/350x350);
  background-size: cover;
  
}
<div></div>

于 2016-11-06T04:02:41.017 回答