Rumah  >  Artikel  >  hujung hadapan web  >  css怎么放图片

css怎么放图片

藏色散人
藏色散人asal
2021-04-25 10:07:2646501semak imbas

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

css怎么放图片

本文操作环境: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(&#39;img/3.jpg&#39;) 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>

效果图:

c40be8101f36e286d6639cb6f10631f.png

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

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

效果图:

b6f0039b69e0a0f7b84e1b9b2840763.png

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视频教程

Atas ialah kandungan terperinci css怎么放图片. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Artikel sebelumnya:css怎么设置背景图片位置Artikel seterusnya:css中怎么设置字体颜色