css中背景相关的属性是哪些?css背景属性的介绍

不言
不言 原创
2018-08-18 13:45:05 4657浏览

css背景有哪些相关属性?下面本篇文章给大家带来关于css背景属性的介绍,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

1、css背景属性之为内容设置背景色:background-color;
属性:
颜色;
inherit;继承父级样式

box.html

<!doctype html>
<html>
<head>
    <mate charset="utf-8">
    <title>背景</title>
    <link href="box.css" type="text/css" rel="stylesheet">
    </head>
    <body>
    <p为内容设置背景色:background-color;</p>
    </body>
    </html>

box.css

body{    
background-color:#123456;
}

2、css背景属性之为内容设置背景为图片background-image:url();
box.css

body{
    background-color:#123456;    
    background-image:url(image.png);
    }

3、css背景属性之固定背景图片background-attachment
(在CSS中使用 background-attachment属性可以将图片固定在浏览器上,如果拖动滚动条,背景图片不会随着网页内容的滚动而滚动,像文字浮在图片上)
属性值:
scroll;背景图片随内容滚动,默认值
fixed; 背景图片固定,不随内容滚动
inherit;继承父类样式

box.css

body{
    background-color:#123456;    
    background-image:url(image.png);    
    background-attachment:fixed;    
    font-size: 45px;
    }

4、css背景属性之背景图片平铺background-repeat;
属性值:
repeat;平铺背景图片;默认
no-repeat;不平铺图片;
repeat-x;在水平方向平铺
repert-y;在竖直方向平铺

box.css

 body{
     background-color:#123456;    
     background-image:url(image.png);    
     background-attachment:fixed;    
     font-size: 45px;    
     background-repeat: repeat-y;    
}

5、css背景属性之背景图片定位background-position
属性值:
top;顶部
center;中间
bottom;底部
right;右边
left;左边
inherit;继承父类样式
样式:
xxxpx,xxxpx;
xxx%,xxx%;
xxxpx,top;

box.css

body{
    background-color:#123456;    
    background-image:url(image.png);    
    background-attachment:fixed;    
    font-size: 45px;    
    background-repeat:no-repeat;    
    background-position:left;
    }

相关推荐:

你不知道的CSS背景—css背景属性全解

详解css之背景background属性

以上就是css中背景相关的属性是哪些?css背景属性的介绍的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。