【发布时间】:2014-06-05 15:08:15
【问题描述】:
我正在制作一个小网页,我希望顶部横幅与一些文本保持在顶部,例如:
HTML:
<div id = "topBanner">
<h1>Some Text</h1>
</div>
CSS:
#topBanner{
position:fixed;
background-color: #CCCCCC;
width: 100%;
height:200px;
top:0;
left:0;
z-index:900;
background: -moz-linear-gradient(top, rgba(204,204,204,0.65) 0%, rgba(204,204,204,0.44) 32%, rgba(204,204,204,0.12) 82%, rgba(204,204,204,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(204,204,204,0.65)), color-stop(32%,rgba(204,204,204,0.44)), color-stop(82%,rgba(204,204,204,0.12)), color-stop(100%,rgba(204,204,204,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(204,204,204,0.65) 0%,rgba(204,204,204,0.44) 32%,rgba(204,204,204,0.12) 82%,rgba(204,204,204,0) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(204,204,204,0.65) 0%,rgba(204,204,204,0.44) 32%,rgba(204,204,204,0.12) 82%,rgba(204,204,204,0) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(204,204,204,0.65) 0%,rgba(204,204,204,0.44) 32%,rgba(204,204,204,0.12) 82%,rgba(204,204,204,0) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(204,204,204,0.65) 0%,rgba(204,204,204,0.44) 32%,rgba(204,204,204,0.12) 82%,rgba(204,204,204,0) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a6cccccc', endColorstr='#00cccccc',GradientType=0 ); /* IE6-9 */
}
/*WebPage Header*/
h1{
font-size:3em;
color:blue;
text-shadow:#CCCCCC 2px 2px 2px, #000 0 -1px 2px;
position: absolute;
width: 570px;
left:50%;
right:50%;
line-height:20px;
margin-left: -285px;
z-index:999;
}
z-index 工作正常,除了因为我在任何时候向下滚动时都使用渐变,横幅后面的元素仍然可见,尽管有些透明。
有没有办法让它们完全不可见?即,我想要做的是让它好像横幅是纯色,即使它是渐变色。
提前感谢您的帮助!
【问题讨论】:
-
使用 Hex 格式的颜色而不是 rgba。
标签: javascript html css gradient