2017-03-22 20 views
0

我试图把中等不透明性,但无法背景图片这样做没有语法错误,这是我的html: -透明度不工作,即使我发现

  
 
<body style="margin:auto;width:100%;height:100%;opacity:0.1;background-image:url('http://farm3.static.flickr.com/2098/2260149771_00cb406fd6_o.jpg')"> 
 
</body>

+0

创建片段 – user3386779

+0

怎么样?我在这里是新的 –

+0

[CSS:设置不透明度的背景图像?]可能的副本(http://stackoverflow.com/questions/4183948/css-set-background-image-with-opacity) –

回答

0

相反调整body elemet,添加一个额外的div来保存背景,更好地将样式分隔成一个css文件。

#background { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
    background-image: url('http://i40.tinypic.com/3531bba.jpg'); 
 
    background-repeat: no-repeat; 
 
    background-attachment: fixed; 
 
    background-size: 100%; 
 
    opacity: 0.4; 
 
}
<!DOCTYPE html> 
 

 
<head> 
 
    <title>Your favourite travle partner</title> 
 
</head> 
 

 
<body> 
 
    <div id="background"></div> 
 
</body>

1

div的使用,而不是body标签。并给该特别高度。

<!DOCTYPE html> 
     <head> 
     <title>Your favourite travle partner</title> 
     </head> 

     <body> 
      <div style="margin:auto;width:100%;height:400px;opacity:0.1;background-image:url('http://www.menucool.com/slider/jsImgSlider/images/image-slider-2.jpg')"> 

    </div> 
     </body> 

     </html>`