透明覆盖背景图像CSS

时间:2013-09-29 16:30:22

标签: css

我有一个全屏背景图片,但我想要一个黑色叠加,不透明度为0.7

这是我的代码:

body { 
  background:url(../images/bg.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;}

我该怎么做?

我的HTML

<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>

    <!-- Basic Page Needs
  ================================================== -->
    <meta charset="utf-8">
    <title>New Year Countdown</title>
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Mobile Specific Metas
  ================================================== -->
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

    <!-- CSS
  ================================================== -->
    <link rel="stylesheet" href="css/style.css">


    <!-- Favicon
    ================================================== -->
    <link rel="shortcut icon" href="images/favicon.ico">


</head>
<body>


<div id="over">k</div>

</body>
</html>

结束必须是不透明度叠加。

2 个答案:

答案 0 :(得分:8)

使用div并指定一个覆盖整个身体的透明类,然后使用:

.transparent {
    background:rgba(255,255,255,0.5);
}

将完成任务。

同时浏览:w3 school image transparency and overlay

答案 1 :(得分:1)

您也可以使用以下技术进行解决:

background-color: black; /* The shade of black that you want*/
background-blend-mode: multiply;