网页背景图不跟随滚动,位置固定不动
在做网页的时候,当背景是一张完整的图片,不动让其跟随滚动条滚动,怎么办?
CSS代码示例-背景颜色属性(background-color):
<html> <head> <title>背景颜色 background-color</title> <style type="text/css"> body {background-color:#99FF00;} </style> </head> <body> <p>这个HTML使用了CSS的background-color属性,将HTML的背景颜色变成翠绿色。<p> </body> </html>
演示结果: 这个HTML使用了CSS的background-color属性,将HTML的背景颜色变成翠绿色。
CSS代码示例-背景图片属性(background-image):
<html><head> <title>背景图片background-image</title></head> <body style="background-image:url(../images/css_tutorials/background.jpg)"> <p>这个HTML使用了CSS的background-image属性,设置了背景图片。<p> </body></html>
演示结果: 这个HTML使用了CSS的background-image属性,设置了背景图片。
CSS代码示例- 背景重复属性(background-repeat)
<html><head> <title>背景重复 background-repeat</title> <style type="text/css"> body {background-image:url(../images/css_tutorials/background.jpg); background-repeat:repeat-y} </style> </head> <body> <p>这个HTML使用了CSS的background-repeat属性,使背景图片竖向重复。<p> <p>常用的background-repeat的属性值有: repeat-x(横向重复),repeat-x(横向重复), no-repeat(不重复)。</p> <p>background-repeat属性要和background-image一起用。</p> </body> </html>
演示结果: 这个HTML使用了CSS的background-repeat属性,使背景图片竖向重复。 常用的background-repeat的属性值有: repeat-x(横向重复),repeat-x(横向重复), no-repeat(不重复)。 background-repeat属性要和background-image一起用。
CSS代码示例-背景附着属性(background-attachment)-[背景图固定不动,不跟随滚动条滚动]:
<html><head> <title>背景附着属性 background-attachment</title> <style type="text/css"> body {background-image:url(../images/css_tutorials/background.jpg); background-repeat:no-repeat; background-attachment:fixed} </style> </head> <body> <p>这个HTML使用了CSS的background-attachment属性,将背景图片固定,不随内容滚动而滚动。<p> <p>背景附着(background-attachment)属性有两个值。一个是scroll,表示随内容滚动而动;一个是fixed,表示固定不动,不受内容滚动影响。缺省值是scroll。</p> <p>background-attachment要和background-image一起用。</p> </body></html>
演示结果: 这个HTML使用了CSS的 background-attachment 属性,将背景图片固定,不随内容滚动而滚动。
背景附着(background-attachment)属性有两个值。一个是scroll,表示随内容滚动而动;一个是fixed,表示固定不动,不受内容滚动影响。缺省值是scroll。
background-attachment要和background-image一起用。
这个HTML使用了CSS的background-attachment属性,将背景图片固定,不随内容滚动而滚动。
背景附着(background-attachment)属性有两个值。一个是scroll,表示随内容滚动而动;一个是fixed,表示固定不动,不受内容滚动影响。缺省值是scroll。
CSS代码示例-背景位置属性(background-position):
<html><head> <title>背景位置属性 background-position</title> <style type="text/css"> body {background-image:url(../images/css_tutorials/background.jpg);background-repeat:no-repeat;background-position:20px 60px}</style> </head> <body> <p>这个HTML使用了CSS的background-position属性。这个属性和background-image属性连在一起使用,决定了背景图片的最初位置。</p> <p>上面的代码表示背景图片的初始位置距离网页最左面20px,距离网页最上面60px。</p> </body></html>
演示结果: 这个HTML使用了CSS的background-position属性。这个属性和background-image属性连在一起使用,决定了背景图片的最初位置。
上面的代码表示背景图片的初始位置距离网页最左面20px,距离网页最上面60px。
CSS代码示例-背景属性(background):
<html><head> <title>背景属性 background</title> <style type="text/css">body{background:#99FF00 url(../images/css_tutorials/background.jpg) no-repeat fixed 40px 100px} </style> </head> <body><p>这个属性是设置背景相关属性的一种快捷的综合写法,包括background-color, background-image, background-repeat, backgroundattachment, background-position。</p> <p>这个HTML所用的背景属性表示,网页的背景颜色是翠绿色,背景是background.jpg图片,图片不重复显示,背景图片不随内容滚动而动,背景图片距离网页最左面40px,距离网页最上面100px。</p> </body></html>
演示结果: 这个属性是设置背景相关属性的一种快捷的综合写法, 包括background-color, background-image, background-repeat, backgroundattachment, background-position。
这个HTML所用的背景属性表示,网页的背景颜色是翠绿色,背景图片是background.jpg图片,背景图片不重复显示,背景图片不随内容滚动而动,背景图片距离网页最左面40px,距离网页最上面100px。
这个属性是设置背景相关属性的一种快捷的综合写法, 包括background-color, background-image, background-repeat, backgroundattachment, background-position。
本文属原创,转载请注明原文:http://www.zhimatong.com/jiaocheng/289.html
为保证教程的实用性及扩大知识面覆盖,如果您有相似问题而未解决,可联系在线客服免费技术支持。
热门主题
相关阅读
- 苹果手机iOS设备,浏览器在 textarea 或 input 中输入文字时页面放大的解决办法
- select选择后直接跳转到其他网站的三种方式
- 详解CSS居中对齐的3种方式15个样例
- Echarts图表基本参数设置说明
- jQuery报错$(this).attr(‘checked‘)undefined/checkbox无法改变其状态的解决方法
- jq .html() 特效无效的解决办法
- 如何将iconfont中的字体图标全部展示在页面中
- HTML特殊字符符号大全
- jQuery清空input的值,清除标签内容的方法
- jQuery 获取相同 class元素的最后一个元素或id
- ajax传递data的三种传递方式
- jQuery跳转页面的3种代码示例