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{ 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>

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

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

css设置背景固定不滚动效果的示例的更多相关文章

  1. css 设置背景图片模糊,内容不模糊

    需求:一个div设置了background: url,现在需要使图片背景模糊,div内的文字清晰显示. 原始代码: <!DOCTYPE html> <html lang=" ...

  2. unity 背景无限循环滚动效果

    背景无限循环滚动效果如下示: 步骤如下: 导入背景图片后,设置图片的格式,如下图: 2.图片格式也可以设置是Texture格式,但是Wrap Mode 一定要是Repeat[重复发生]:然后记得App ...

  3. img只显示图片一部分 或 css设置背景图片只显示图片指定区域

    17:14 2016/3/22img只显示图片一部分 或 css设置背景图片只显示图片指定区域 background-position: 100% 56%; 设置背景图片显示图片的哪个坐标区域,图片左 ...

  4. CSS 设置背景透明度,不影响子元素

    由于 opacity 属性能被子元素继承,使用它设置父元素背景透明度时也会影响子元素. 解决方法: 1> 使用 RGBA Example .classname { /* RGBa, 透明度0.6 ...

  5. 解决css设置背景透明,文字不透明

    设置元素的透明度:  -moz-opacity:0.8; /*在Firefox中设置元素透明度  filter: alpha(opacity=80); /*ie使用滤镜设置透明   但是当我们对一个标 ...

  6. CSS——设置背景

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. div+css实现表头固定内容滚动表格

    <div class="m-demo"> <table> <thead> <tr><th>定宽a</th>& ...

  8. (转)background-position—CSS设置背景图片的位置

    background-position :在 CSS 中通过 background-position 属性可以调整背景图片的位置.因为在默认情况下背景图片都是从设置了 background-posit ...

  9. 使用CSS设置背景图片,图片比较大,完全显示在一个DIV中

    做的时候想要边框为比较好看的样式,需要UI切图并且放在div中,看起来会好看点 像这样的,我随便挑选了一个,UI帮我切图出来 需要把这个图片填到相应的div里面,但是很显然碰到一个问题,图片太大,而且 ...

随机推荐

  1. 《tortoisegit》 Network error:Connection refused

    在用tortoisegit克隆的时候,或者push的时候出现错误提示: 尝试修改:c:\windows\system32\drivers\etc\services 中的ssh端口,但是发现是22端口, ...

  2. 菜鸟调错(三)——Jboss与jdk版本号不兼容导致WebService调用出错

    环境: jdk1.6 Jboss 5.1.0.GA 问题描写叙述: EJB公布webserivce已经成功,而且可以成功訪问wsdl文件: 使用axis1自带的sample/client下的类Dyna ...

  3. vue 父子组件传值的另外一种方式 provide inject

    1.文档说明 https://cn.vuejs.org/v2/api/#provide-inject 2.实例 element ui的dropdown组件 dropdown.vue: provide( ...

  4. 如何发布本地maven项目jar包部署到nexus私服?

    首先在我们的pom里面描述我们要部署的地址: <distributionManagement> <repository> <id>release</id> ...

  5. Android 屏幕自适应方向尺寸

    最近感觉要被屏幕适配玩死了…… 安卓的手机为虾米不能像苹果那样只有几个分辨率呢?为什么呢!!!!!!!阿门…… 目前想到有两种解决办法…… 第一种:   HTML5+CSS3+WebView交互……目 ...

  6. centos7 配置PPTP、L2TP、IPSec服务

    首先,推荐跑下面的脚本: https://github.com/BoizZ/PPTP-L2TP-IPSec-VPN-auto-installation-script-for-CentOS-7 这个脚本 ...

  7. 在Cocos2d-X中使用xml

    XML就可以扩展标记语言.在游戏开发中,经常使用于保存游戏信息,如最高分,游戏等级.等信息,和描写叙述一些资源等,我第一次使用xml是在使用CCAnimation创建动画中,使用plist文件载入动画 ...

  8. Scala, Groovy, Clojure, Jython, JRuby and Java ----我们的工作语言

    在曾经的一封邮件中,我指出在众多改变中,最明显的一个就是:在java领地上的JVM上使用其它流行的语言的发展变得越来越快.一些老的和新的创建的基于JVM的语言---JRuby 和 Jython ,Ja ...

  9. H5 input 聚焦 置顶

    myFocus (e) { this.active = true function getElementTop(element){ try { var actualTop = element.offs ...

  10. shell中的find和xargs详细解析