王朝百科
分享
 
 
 

background

王朝百科·作者佚名  2010-04-30  
宽屏版  字体: |||超大  

background背景 (background) 属性定义元素的背景效果

元素的背景区包括前景之下直到边框边界的所有空间。因此,内容框与内边距都是元素背景的一部分,且边框画在背景上。

CSS 允许应用纯色作为背景,也允许使用背景图像创建相当复杂的效果;CSS 在这方面的能力远远在 HTML 之上。

background 是用于在一个声明中设置所有背景属性的一个简写属性。

格式: background: {属性值}

继承性: NO

可能的值:

background-color

background-image

background-repeat

background-attachment

background-position

注:可以在此声明中声明1到5个背景属性

例:

<style type="text/css">

body

{

background: #ff0000 url(/i/eg_bg_03.gif) no-repeat fixed center;

}

</style>

background属性详解及实例:background-color:{颜色值|transparent(默认值)} 属性设置元素的背景颜色。

color 颜色值可以是颜色名称、rgb 值或者十六进制数。

transparent 默认。背景颜色为透明。

例:

body

{

background-color: #00FF00

}

1.background-image:{URL(url)} 把图像设置为背景。

url(URL) 指向图像的路径。

none 默认。无背景图像。

例:

body

{

background-image: url(pic.jpg);

}

2.background-repeat:{repeat|no-repeat|repeat-X|repeat-Y} 设置背景图像是否及如何重复。

repeat 默认。背景图像将在垂直方向和水平方向重复。

repeat-x 背景图像将在水平方向重复。

repeat-y 背景图像将在垂直方向重复。

no-repeat 背景图像将仅显示一次。

例:

body

{

background-image: url(pic.jpg);

background-repeat: no-repeat;

}

3.background-attachment:{fixed|scroll} 背景图像是否固定或者随着页面的其余部分滚动

scroll 默认。背景图像会随着页面其余部分的滚动而移动。

fixed 当页面的其余部分滚动时,背景图像不会移动。

例:

body

{

background-attachment: fixed;

background-image: url(pic.jpg);

}

4.background-position:{位置值} 属性设置背景图像的起始位置。

top left

top center

top right

center left

center center

center right

bottom left

bottom center

bottom right

x% y%

xpos ypos

例:

body

{

background-image: url(pic.jpg);

background-position: top;

}

用javascript改变背景图片

例:

<html>

<head>

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

<title>新建网页 1</title>

<script language="javascript">

function hi()

{

document.body.style.background="no-repeat url(../images/asp_logo1.gif) 50% 50%";

}

</script>

</head>

<body>

<input type="button" value="显示" onclick="javascript:hi()">

</body>

</html>

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
如何用java替换看不见的字符比如零宽空格&#8203;十六进制U+200B
 干货   2023-09-10
网页字号不能单数吗,网页字体大小为什么一般都是偶数
 干货   2023-09-06
java.lang.ArrayIndexOutOfBoundsException: 4096
 干货   2023-09-06
Noto Sans CJK SC字体下载地址
 干货   2023-08-30
window.navigator和navigator的区别是什么?
 干货   2023-08-23
js获取referer、useragent、浏览器语言
 干货   2023-08-23
oscache遇到404时会不会缓存?
 干货   2023-08-23
linux下用rm -rf *删除大量文件太慢怎么解决?
 干货   2023-08-08
刀郎新歌破世界纪录!
 娱乐   2023-08-01
js实现放大缩小页面
 干货   2023-07-31
生成式人工智能服务管理暂行办法
 百态   2023-07-31
英语学习:过去完成时The Past Perfect Tense举例说明
 干货   2023-07-31
Mysql常用sql命令语句整理
 干货   2023-07-30
科学家复活了46000年前的虫子
 探索   2023-07-29
英语学习:过去进行时The Past Continuous Tense举例说明
 干货   2023-07-28
meta name="applicable-device"告知页面适合哪种终端设备:PC端、移动端还是自适应
 干货   2023-07-28
只用css如何实现打字机特效?
 百态   2023-07-15
css怎么实现上下滚动
 干货   2023-06-28
canvas怎么画一个三角形?
 干货   2023-06-28
canvas怎么画一个椭圆形?
 干货   2023-06-28
canvas怎么画一个圆形?
 干货   2023-06-28
canvas怎么画一个正方形?
 干货   2023-06-28
中国河南省郑州市金水区蜘蛛爬虫ip大全
 干货   2023-06-22
javascript简易动态时间代码
 干货   2023-06-20
感谢员工的付出和激励的话怎么说?
 干货   2023-06-18
 
>>返回首页<<
 
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有