我想尝试编写一个有点透明的固定标头。
任何想法,示例代码,教程?如果可能的话,我想用CSS实现它。我猜需要玩不透明度(CSS3)。
答案 0 :(得分:11)
全屏jsFiddle:http://fiddle.jshell.net/NathanJohnson/LrNBt/show/
jsFiddle:http://jsfiddle.net/NathanJohnson/LrNBt/
<div id="header">
<div id="header-content">
<h1>Here is some heading text :)</h1>
<p>Here is some more content of the header...</p>
</div>
</div>
body {
font-family: arial, sans-serif;
padding: 0;
margin: 0;
}
#header {
background-color: black;
/*Opacity start*/
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=80);
-moz-opacity: 0.80;
-khtml-opacity: 0.8;
opacity: 0.8;
/*Opacity end*/
color: white;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 150px;
padding: 0;
margin: 0;
}
#header #header-content {
margin: 10px;
}
rgba()
代替opacity
:#header {
background-color: rgba(0, 0, 0, 0.8);
color: white;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 150px;
padding: 0;
margin: 0;
}
#header #header-content {
margin: 10px;
}
我希望这会有所帮助。
答案 1 :(得分:2)
使用Firebug分析他们的代码:
#header {
left: 0;
position: fixed;
top: 0;
width: 100%;
z-index: 90;
background: url("../images/bg-header.png") repeat-x scroll 0 0 transparent;
height: 247px;
}
而不是使用图像:
background: #000;
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;