html - 在背景图像上使用 css 渐变

标签 html css gradient

我一直在尝试在我的背景图像上使用线性渐变,以便在我的背景底部获得从黑色到透明的渐变效果,但似乎无法让它显示出来。

我在这里阅读了其他案例和示例,但没有一个对我有用。我只能看到渐变或图像,但看不到两者。 这是 link

只需点击第一个标志,忽略那个效果,我正在尝试的是在那之后整个站点的正文中。

这是我的CSS代码:

body {
  background: url('http://www.skrenta.com/images/stackoverflow.jpg') no-repeat, -webkit-gradient(linear, left top, left bottom, from(rgba(0, 0, 0, 0.1)), to(rgba(0, 0, 0, 1)));
}

最佳答案

好的,我通过在行尾添加背景图片的 url 解决了这个问题。

这是我的工作代码:

.css {
  background: 
   linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0) 59%, rgba(0, 0, 0, 0.65) 100%),
   url('https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-icon.png?v=c78bd457575a') no-repeat;
  height: 200px;
}
<div class="css"></div>

关于html - 在背景图像上使用 css 渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16589519/

相关文章:

html - 防止页面尺寸减小时页面内容越界

html - 嵌套元素的边距

javascript - 根据宽高比更改图像的宽度

html - 基于 Shadow DOM 根的字体大小 css 值

html - CSS 在 Chrome 中不起作用,但在 Firefox 中起作用

javascript - 包括 HTML 页面和样式吗?

html - 如何在 bootstrap 字形周围添加一个圆圈

javascript - 删除 bootstrap 标签输入中的 "x"

android - 三个相邻矩形的颜色连续变化

android - 用于线性布局的 xml 中的渐变