background和background-image什么区别

fancyoo1 2009-07-23 10:17:10
想请教下background和background-image什么区别啊?background里面可以设这很多的相关背景属性,background-image只是设置背景图片。下面2个CSS
<style type="text/css">
.css1{
background-image:url(b_1.jpg) no-repeat;
}
.css2{
background:url(b_2.jpg) no-repeat;
}
</style>
调用
<input type="submit" value="登 录" class="css1" onMouseOver="this.className='css2'"/>
为什么用background按钮的背景图片能看到,而设置成background-image却看不到图片呢,不解。。。。谁能解释一下啊,谢谢了
...全文
7927 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaonix111 2011-10-11
  • 打赏
  • 举报
回复
000
zw393 2009-08-16
  • 打赏
  • 举报
回复 1
语法:
background : background-color || background-image || background-repeat || background-attachment || background-position
取值:
该属性是复合属性。请参阅各参数对应的属性。
默认值为:transparent none repeat scroll 0% 0%。

说明:
设置对象的背景样式。
如使用该复合属性定义其单个参数,则其他参数的默认值将无条件覆盖各自对应的单个属性设置。
例如:设置 background : white 等于设置 background : white none repeat scroll 0% 0% 。如果在此之前设置了 background-image 属性,则其设置将被 background-image 的默认值 none 覆盖。
背景样式属性的作用区域为对象的内容区域与内补丁( padding )区域。不包括边框( border )与外补丁( margin )区域。尽管该属性不可继承,但如果未指定,其父对象的背景颜色和背景图将在对象下面显示。
对应的脚本特性为 background 。

-------

语法:
background-image : none | url ( url )
取值:
none : 默认值。无背景图
url ( url ) : 使用绝对或相对 url 地址指定背景图像

说明:
设置或检索对象的背景图像。
当背景图像与背景颜色( background-color )都被设定了时,背景图片将覆盖于背景颜色之上。
此属性对于 currentStyle 对象而言是只读的。对于其他对象而言是可读写的。
对应的脚本特性为 backgroundImage 。
officeeasy 2009-07-27
  • 打赏
  • 举报
回复
加载图片
浴火_凤凰 2009-07-24
  • 打赏
  • 举报
回复
submit可以使用背景图片吗?
xuqingkai 2009-07-23
  • 打赏
  • 举报
回复
这个地方用在input标签上等,IE经常出现不兼容
我通常的原则是
尽量只用background,

所以,我这样写,
.css1{
background:url(b_1.jpg);
background-repeat:no-repeat;
}

应该就可以了
算是hack吧
夜雨_Jason 2009-07-23
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 fancyoo1 的回复:]
我现在改成这样了,发现还是css1还是不显示,CSS2正常显示。。。。。让我很纳闷。。。

.css1{
background-image:url(b_1.jpg);
background-repeat:no-repeat;
}

[/Quote]
FF可以,IE不可以
fancyoo1 2009-07-23
  • 打赏
  • 举报
回复
我现在改成这样了,发现还是css1还是不显示,CSS2正常显示。。。。。让我很纳闷。。。

.css1{
background-image:url(b_1.jpg);
background-repeat:no-repeat;
}
.css2{
background:url(b_1.jpg) no-repeat;
}

mute_solo 2009-07-23
  • 打赏
  • 举报
回复
background属性是整体设置的,background image是background的属性之一,background的属性包括
background-color
background-image
background-repeat
background-attachment
background-position,
你看不到图片是因为设置错误,不能加no-repeat属性,应该写为:
background-image:url("some.jpg"); background-repeat:no-repeat;分开写。
gadfly1981 2009-07-23
  • 打赏
  • 举报
回复
书上说,background-image : none | url ( url )
可见是没no-repeat

设置repeat可用background-repeat : repeat | no-repeat | repeat-x | repeat-y

background是一个综合写法
background : background-color || background-image || background-repeat || background-attachment || background-position
省略一些属性也能工作
浪尖赏花 2009-07-23
  • 打赏
  • 举报
回复
background包括
color: Any of the range of color values available to the backgroundColor property.
image: Any of the range of image values available to the backgroundImage property.
repeat: Any of the range of repeat values available to the backgroundRepeat property.
attachment: Any of the range of attachment values available to the backgroundAttachment property.
position:Any of the range of position values available to the backgroundPosition property

比如
.style1{background:beige url(sphere.jpg) no-repeat top center}

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧