【发布时间】:2015-03-19 13:55:53
【问题描述】:
我有一个网站,其主体包含固定背景图像和一个包含透明径向渐变层的 div 类。如何使类中的元素不透明并出现在背景渐变和背景图像之上?
CSS:
$body-color1: #f2009f;
$body-color2: #218bdb;
// Solution 1. However, unable too get content on top of gradient and backgourn image
html { min-height:100%; } /* to get the gradient to stetch to the bottom of the view port */
body {
background: $body-color2;
background: url('http://i.huffpost.com/gen/964776/thumbs/o-CATS-KILL-BILLIONS-facebook.jpg') no-repeat center center fixed;
background-attachment: fixed;
// background-size: cover;
}
.bg-img {
background: -moz-radial-gradient(center, ellipse cover, $body-color1 0%, $body-color2 100%); /* FF3.6+ */
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0 $body-color1), color-stop(100%,$body-color2)); /* Chrome,Safari4+ */
background: -webkit-radial-gradient(center, ellipse cover, $body-color1 0%,$body-color2 100%); /* Chrome10+,Safari5.1+ */
background: -o-radial-gradient(center, ellipse cover, $body-color1 0%,$body-color2 100%); /* Opera 12+ */
background: -ms-radial-gradient(center, ellipse cover, $body-color1 0%,$body-color2 100%); /* IE10+ */
background: radial-gradient(center, ellipse cover, $body-color1 0%,$body-color2 100%); /* W3C */
opacity: 0.5;
z-index: 0;
}
HTML:
<div class="bg-img">Insert large body of text here or elements.</div>
【问题讨论】:
-
“我如何使类中的元素不透明”——不使用
opacity——不透明度适用于包括其所有内容的元素。 -
如果我这样做,我将失去图像顶部的透明渐变。图像将被覆盖。有没有办法在图像顶部仍然具有透明渐变效果,同时具有不透明元素?
-
渐变也应该与
rgba颜色一起使用。