简体   繁体   English

透明背景色不起作用

[英]transparent background-color not working

i have this issue with bootstrap 4: i'm working on a web page and i've put a fixed background with css. 我在Bootstrap 4中遇到这个问题:我正在网页上工作,并且已经将CSS固定为背景。 I want to put multiple <div> one under another, with some transparent space between them, in order to see pieces of the background image in these transparent spaces. 我想将多个<div>一个接一个地放置在另一个之间,并在它们之间留有一定的透明空间,以便在这些透明空间中看到背景图像。 The problem is that bootstrap (i guess) makes every kind of background text to be white-coloured so the transparent thing doesn't work. 问题是,引导程序(我想)会使每种背景文本都变成白色,因此透明的东西不起作用。 I created a "spazioVuoto" class in css that should make the background transparent, but it doesn't. 我在CSS中创建了一个“ spazioVuoto”类,该类应使背景透明,但事实并非如此。 Can anyone help me? 谁能帮我?

PS. PS。 if you want to see an example of what i'm talking about, look at http://it.diesel.com/it/ 如果您想查看我正在谈论的示例,请访问http://it.diesel.com/it/

here is a codepen example https://codepen.io/anon/pen/ooJqVK 这是一个代码笔示例https://codepen.io/anon/pen/ooJqVK

this is my code 这是我的代码

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

.spazioVuoto {
    background-color: transparent;
    padding: 5em;
}

The problem here is that your body have a backgournd-color:#fff, so even if spazioVuoto have background transparent the color will be still white because of that. 这里的问题是您的身体具有背景色:#fff,因此即使spazioVuoto具有背景透明色,其颜色也仍会是白色。 Try to change it (spazioVuoto background-color) to red and you will see that it will work. 尝试将其(spazioVuoto背景色)更改为红色,您会发现它会起作用。 So you have to put the body background to transparent and then work on other containers to set their background-color. 因此,您必须将主体背景设置为透明,然后在其他容器上工作以设置其背景颜色。

html { 
  background: url("w3schools.com/w3css/img_fjords.jpg") 
  no-repeat center center fixed; 
  -webkit-background-size: cover; 
  -moz-background-size: cover; 
  -o-background-size: cover;
  background-size: cover;
} 
body {  
  background-color:transparent !important;
} 
.spazioVuoto { 
  background-color: transparent;
  padding: 5em; 
}
.container { 
  max-width: 100% !important;
  background-color: #fff;
  width: 100% !important;
  padding: 1% 20% !important;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM