您的位置:首页 >综合精选 >

css怎么放图片

跟大家讲解下有关css怎么放图片,相信小伙伴们对这个话题应该也很关注吧,现在就为小伙伴们说说css怎么放图片,小编也收集到了有关css怎么放图片的相关资料,希望大家看到了会喜欢。

css放图片的方法:1、使用background简写属性在设置背景时引入图片;2、直接使用background-image属性引入背景图片。

本文操作环境:windows7系统、HTML5&&CSS3版、Dell G3电脑。

css怎么放图片?

随着互联网的发展,网速不断提升,我们现在的网页也变的更加丰富起来,除了能够传输文字外,我们还可以传输图片。我们该如何使用css在网页中放图片?下面我们俩看一下使用css在网页中放图片的方法。

css可以使用background简写属性在设置背景时引入图片,也可以使用background-image属性引入背景图片。background-image属性为元素设置背景图像。

使用background简写属性引入图片:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style> body { background: #00ff00 url('img/3.jpg') no-repeat fixed center; } </style> </head> <body> <p>This is some text</p> <p>This is some text</p> <p>This is some text</p> <p>This is some text</p> <p>This is some text</p> <p>This is some text</p> <p>This is some text</p> <p>This is some text</p> <p>This is some text</p> <p>This is some text</p> <p>This is some text</p> </body> </html>

效果图:

使用background-image属性在网页中放入图片:

<html> <head> <style type="text/css"> body {background-image:url(/i/eg_bg_04.gif);} </style> </head> <body></body> </html>

效果图:

background 简写属性:

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

可以设置如下属性:

background-color background-position background-size background-repeat background-origin background-clip background-attachment background-image

如果不设置其中的某个值,也不会出问题,比如 background:#ff0000 url('smiley.gif'); 也是允许的。

通常建议使用这个属性,而不是分别使用单个属性,因为这个属性在较老的浏览器中能够得到更好的支持,而且需要键入的字母也更少。

background-image 属性:

background-image 属性为元素设置背景图像。

元素的背景占据了元素的全部尺寸,包括内边距和边框,但不包括外边距。

默认地,背景图像位于元素的左上角,并在水平和垂直方向上重复。

提示:请设置一种可用的背景颜色,这样的话,假如背景图像不可用,页面也可获得良好的视觉效果。

属性值:

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

none 默认值。不显示背景图像。

inherit 规定应该从父元素继承 background-image 属性的设置。

【推荐学习:css视频教程】

以上就是css怎么放图片的详细内容,更多请关注php中文网其它相关文章!

来源:php中文网

免责声明:本文由用户上传,如有侵权请联系删除!