zoukankan      html  css  js  c++  java
  • css设置背景固定不滚动效果的示例

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

    背景固定不滚动各位看到最多的无非就是QQ空间了,我们在很多的空间都可以看到内容滚动而北京图片不滚动了,下文整理了几个关于背景固定不滚动css代码。

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

    <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">

     

    <html xmlns="http://www.w3.org/1999/xhtml">

     

    <head>

     

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

     

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

     

    *{ margin:0; padding:0;}

     

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

     

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

     

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

     

    .box{ position:absolute; left:50%; top:50%; 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; 300px; height:300px; text-align:center; border:1px solid #f00; background:#fff;}

     

    </style>

     

    </head>

     

    <body>

     

    <div class="container">

     

    <script type="text/javascript">

     

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

     

    document.write('<center>脚本学堂,div+css教程,禁止背景图片滚动。</center>');

     

    }

     

    </script>

     

    </div>

     

    <div class="bg"></div>

     

    <div class="box"><div class="info">我就不动</div></div>

     

    </body>

     

    </html>

    二、css设置body背景图片固定不动内容滚动

    css中使body背景图片固定不动内容滚动:
     

    style="background-attachment: fixed"


    例子:
     

    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;

     

    }

    三、css固定背景图片不滚动

    例子:
     

    <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</title>

     

    </head> 

     

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

     

    </body> 

     

    </html>

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

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

    <html>

     

    <head>

     

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

     

    <title>不动的背景图</title>

     

    <style type="text/css">

     

    body{

     

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

     

    background-repeat:no-repeat;

     

    background-position:center;

     

    background-attachment:fixed;

     

    }

     

    </style>

     

    </head>

     

    <body>

     

    <div style="position:absolute;top:400px;left:200px;height:500px;color:red">

     

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

     

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

     

    </div>

     

    </body>

     

    </html>

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

    <html>

     

    <head>

     

    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

     

    <title>不动的背景图</title>

     

    <style type="text/css">

     

    body{

     

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

     

    background-repeat:no-repeat;

     

    background-position:center;

     

    }

     

    </style>

     

    </head>

     

    <body bgproperties="fixed">

     

    <div style="position:absolute;top:400px;left:200px;height:500px;color:red">

     

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

     

    </div>

     

    </body>

     

    </html>

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

  • 相关阅读:
    端口映射到公网工具
    C# app.config文件配置和修改
    C#基本知识点-Readonly和Const的区别
    C#知识点-StopWatch-计时
    python with open as f写中文乱码
    程序员不要去这样的公司
    关于老系统的重构和优化选择
    .Net Remoting 调用远程对象
    自定义的Config节点及使用
    前台线程和后台线程区别与使用技巧
  • 原文地址:https://www.cnblogs.com/huangf714/p/5876147.html
Copyright © 2011-2022 走看看