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>

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

  • 相关阅读:
    octotree神器 For Github and GitLab 火狐插件
    实用篇如何使用github(本地、远程)满足基本需求
    PPA(Personal Package Archives)简介、兴起、使用
    Sourse Insight使用过程中的常使用功能简介
    Sourse Insight使用教程及常见的问题解决办法
    github 遇到Permanently added the RSA host key for IP address '192.30.252.128' to the list of known hosts问题解决
    二叉查找树的C语言实现(一)
    初识内核链表
    container_of 和 offsetof 宏详解
    用双向链表实现一个栈
  • 原文地址:https://www.cnblogs.com/huangf714/p/5876147.html
Copyright © 2011-2022 走看看