CSS:透明与不透明度:0

标签 css background-image opacity transparent

我想将页面的整个背景设置为图像。我使用以下代码设置 html 背景。我注意到 body 背景仍然设置为白色。我试过“不透明度:0;”但这使得 body 中的每个元素都是“不透明度:0;” (这不是我需要的)。我尝试了“背景:透明;”,这似乎可行。但我不明白不透明度:0 和透明之间的区别。有人可以通俗易懂地解释一下吗?

@import url(//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css);

html{
    background:url('https://stocksnap.io/img-thumbs/960w/22629E3D46.jpg') no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
}

body{
    padding-top: 50px;
    background:transparent;
}

.header{
    background-color: white;
}

.body{
}

.box{
    border-radius: 3px;
    box-shadow:0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
    padding:10px 25px;
    text-align: right;
    display: block;
    margin-top: 60px;
    background-color: white;
    opacity: .8;
    transition: all 0.5s ease 0s;
}

.popup{
    background-color: blue;
}

.box:hover{
    opacity: .9;
    transition: all 0.5s ease 0s;
}

.box-icon{
    background-color:#57a544;
    border-radius: 50%;
    display: table;
    height:100px;
    width:100px;
    margin:0 auto;
    margin-top:-61px;
}

.box-icon span{
    color:#fff;
    display: table-cell;
    text-align: center;
    vertical-align: middle;
}

.info h4{
    font-size: 26px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.info p{
    color:
    font-size: 16px;
    padding-top: 10px;
    text-align: justify;
}

.info a{
    background-color: #03a9f4;
    border:2px;
    box-shadow:0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12);
    color:#fff;
    transition: all 0.5s ease 0s;
}

.info a:hover{
    background-color: #0288d1;
    box-shadow:0 2px 3px 0 rgba(0, 0, 0, 0.16), 0 2px 5px 0 rgba(0, 0, 0, 0.12);
    color: #fff;
    transition:all 0.5s ease 0s;
}
<!DOCTYPE html>
<html>

<head>

  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
  <link rel="stylesheet" href="style.css">
  <link rel='stylesheet prefetch' href='http://netdna.bootstrapcdn.com/font-awesome/4.0.2/css/font-awesome.min.css'>
  <link rel="shortcut icon" type="image/png" href="favicon/favicon-nav-logo.ico"/>

</head>
<body>
    <div class="container">
        <div class="row body">
            <div class="col-xs-12 col-sm-6 col-lg-6">
                <div class="box">
                    <div class="info">
                        <h4 class="text-center">Title</h4>
                        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Enim omnis veritatis quia labore quas eveniet nesciunt dolorum, totam quibusdam aspernatur dignissimos consectetur illum vero, suscipit, beatae accusantium quis perspiciatis natus.</p>
                    </div>
                </div>
            </div>
            
        </div>
    </div>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</body>
</html>

条款?

最佳答案

为什么不把背景直接设置到body呢? <强> jsBin demo

html, body{
    height:100%;
    margin:0;
}

body{
    padding-top: 50px;
    background: url('image.jpg') fixed 50% / cover;
}

不透明度与背景无关,但与元素不透明度状态有关。
background: transparent;为透明背景。

将元素设置为 opacity:0; 将使子元素“消失”,因为该属性已设置为父元素。

关于CSS:透明与不透明度:0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28255144/

相关文章:

html - HTML/CSS 中条形图的缩放问题

html - 打开/关闭模态时防止内容移动

jquery - 使用 fadeIn() 循环切换背景图像

wpf - XAML IsMouseOver 和 IsEnabled 的奇怪冲突导致按钮在禁用时显示为事件状态

html - CSS 中的背景图像不透明度(在 Dreamweaver 中工作)

css - Chrome 没有完全渲染 css

php - 参数化背景 css 属性的 url 属性

css - 想要使用 CSS 将 imagine 放置在 DIV 中但不显示图像?

php - Javascript document.body.style.backgroundImage 导致 php mysql 查询运行?

swift - 无法更改导航栏不透明度