[css设置背景固定不滚动效果图]css设置背景固定不滚动效果的示例

更新时间:2019-10-19    来源:背景特效    手机版     字体:

【www.bbyears.com--背景特效】

一、css设置背景不滚动的效果









css禁止背景滚动 - www.jbxue.com<111cn.nettyle type="text/css">

*{ margin:0; padding:0;}

html,body{ width:100%; height:100%; overflow:auto; position:relative;}

.container{ width:100%; height:100%; overflow:auto;}

.bg{ background:#000000;opacity:0.5; filter:alpha(opacity=50); position:absolute; z-index:1; overflow:auto; width:100%; height:100%; left:0; top:0;}

.box{ position:absolute; left:50%; top:50%; width:300px; z-index:11; height:300px; line-height:300px; color:#f60; font-weight:bold; font-size:20px;}

.info{ position:absolute; left:-50%; top:-50%; z-index:10; width:300px; height:300px; text-align:center; border:1px solid #f00; background:#fff;}

</style>

</head>

<body>



<script type="text/javascript">

for(var i=0;i<150;i++){

document.write('<center>脚本学堂,div+<a href="http://www.bbyears.com/clist-10-1.html" target="_blank" class="keylink">css教程</a>,禁止背景图片滚动。</center>');

}

</script>





我就不动

</body>

</html></pre><p>二、css设置body背景图片固定不动内容滚动</p><p>css中使body背景图片固定不动内容滚动:<br/> </p><p>style="background-attachment: fixed"</p><p><br/>例子:<br/> </p><pre class=\"brush:css;toolbar:false\">body {

 background-image: url(images/dbg.jpg);

 background-repeat: no-repeat;

 font-family: "宋体";

 font-size: 12px;

 line-height: normal;

 font-weight: normal;

 color: #FFFFFF;

 background-attachment: fixed;

}</pre><p>三、css固定背景图片不滚动</p><p>例子:<br/> </p><pre class=\"brush:css;toolbar:false\"><html> 

<head> 

<style type="text/css"> 

body { 

background-image:url('/images/wall1.jpg'); 

background-repeat: no-repeat; 

background-attachment: fixed;

} 

#codefans_net{

height:1628px;

}

</style> 

<title>CSS固定背景图片不滚动代码 - www.jbxue.com

 

<111cn.netv id="codefans_net">拖动滚动条,文字会消失,背景依然存在。

 

四、css设置页面背景不动只滚动条动效果

方法一(页面背景不动只滚动条动):
 







不动的背景图



body{

background-image:url(images/0004.jpg);

background-repeat:no-repeat;

background-position:center;

background-attachment:fixed;

}









通过CSS设置网页滚动条滚动但是页面背景图片静止不动(请查看源代码)

注意:background-image:url(images/0004.jpg); 设置一张相对路径下存在的背景图片





 
方法二(页面背景不动只滚动条动):
 







不动的背景图



body{

background-image:url(images/0004.jpg);

background-repeat:no-repeat;

background-position:center;

}









请查看源代码(使用了BODY的bgproperties="fixed"属性)





从上面的几个例子来看背景不滚动都是通过定位来解决了,上面的例子各有千秋了各位可以选择合适自己的效果代码。

本文来源:http://www.bbyears.com/wangyetexiao/74063.html

热门标签

更多>>

本类排行