• 技术文章 >web前端 >前端问答

    css怎么放图片

    藏色散人藏色散人2021-04-25 10:07:26原创41439

    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>

    效果图:

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

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

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:css
    上一篇:css怎么设置背景图片位置 下一篇:自己动手写 PHP MVC 框架(40节精讲/巨细/新人进阶必看)

    相关文章推荐

    • css如何让隐藏的元素显示出来• css如何添加背景• css如何让div隐藏• css如何让图片旋转• css怎么设置背景图片位置
    1/1

    PHP中文网