我想将页面的整个背景设置为图像。我用以下代码设置html背景。我注意到身体背景仍然是白色的。我试过'不透明度:0;'但这使得身体中的每个元素都变成了“不透明度:0;” (这不是我需要的)。我试过'背景:透明;'这似乎有效。但是我不明白Opacity:0和Transparent之间的区别。有人可以用外行术语来解释吗?
@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>
术语
答案 0 :(得分:0)
为什么不直接将背景设置为body
?的 jsBin demo 强>
html, body{
height:100%;
margin:0;
}
body{
padding-top: 50px;
background: url('image.jpg') fixed 50% / cover;
}
不透明度与背景无关,但与元素不透明度状态无关
background: transparent;
是一个透明的背景。
将元素设置为opacity:0;
会让孩子们“消失”#34;因为该属性已设置为父级。