CSS背景边框

2018-11-03  本文已影响0人  Frewen

背景样式

常用的背景样式
background-color: gray;
background-color: #808080;
background-color: rgb(128,128,128);
body{background-image: url("images/bg.jpg");}
描述
repeat 默认。背景图像将在垂直方向和水平方向重复
repeat-x 背景图像将在水平方向重复
repeat-y 背景图像将在垂直方向重复
no-repeat 背景图像将仅显示一次
inherit 规定应该从父元素继承background-repeat属性的设置

background-position属性值:

①使用关键字:background-position:center left

②使用百分数值:background-position: 50% 50%

③使用长度值:background-position:300px 100px

/*背景样式综合使用*/
background: #00ff00 url(image/bg.jpg)  no-repeat center;

background-attachment属性设置背景图像是否固定或者随着页面的其余部分滚动。

  1. scroll:默认值。背景图像会随着页面的滚动而移动。
  2. fixed:当页面的其余部分滚动时,背景图像不会移动。
background-size
描述
length 以浮点数字和单位组成的长度值来设置背景图像的宽度和高度,如果只设置第一个值,则第二个值会被设置为"auto"
percentage 以父元素的百分比来设置背景图像的宽度和高度,如果只设置第一个值,则第二个值会被设置为"auto"
cover 保持背景图像本身宽高比例,将图片缩放到正好完全覆盖所定义背景的区域
contain 保持背景图像本身宽高比例,将图片缩放到宽度或高度正好适应所定义背景的区域
cover和contain
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>背景</title>
    <style type="text/css">
        div{width: 700px;height: 400px;border: 2px solid plum;background-repeat: no-repeat;
            background-image: url(img/design.jpg);background-size: cover;}
    </style>
</head>
<body>
    <div>图片尺寸</div>
</body>
</html>
background-origin

默认是padding-box

background-origin
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"> 
    <style> 
        div{border:10px solid black;padding:35px;background-image:url(img/smiley.gif);
        background-repeat:no-repeat;background-position:0px 0px;}
        #div1{background-origin: padding-box;}
        #div2{background-origin:content-box;}
    </style>
</head>
<body>
    <p>背景图像边界框的相对位置:</p>
    <div id="div1">
      CSS 允许应用纯色作为背景,也允许使用背景图像创建相当复杂的效果。CSS 在这方面的能力远远在 HTML 之上。CSS 允许应用纯色作为背景,也允许使用背景图像创建相当复杂的效果。CSS 在这方面的能力远远在 HTML 之上。
    </div>
    <p>背景图像的相对位置的内容框:</p>
    <div id="div2">
      CSS 允许应用纯色作为背景,也允许使用背景图像创建相当复杂的效果。CSS 在这方面的能力远远在 HTML 之上。CSS 允许应用纯色作为背景,也允许使用背景图像创建相当复杂的效果。CSS 在这方面的能力远远在 HTML 之上。
    </div>
</body>
</html>
background-clip
描述
border-box 从边框区域向外裁剪背景
padding-box 从补白区域向外裁剪背景
content-box 从内容区域向外裁剪背景
background-clip与background-origin
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"> 
    <style>
        #example1 {
            width: 800px;
            height: 450px;
            border: 20px dotted black;
            padding: 50px;
            background-image: url(img/girl.jpg);
            background-size: 100% 100%;
            background-repeat: no-repeat;           
            background-clip: padding-box;/*padding-box以外的都要剪辑掉*/
            background-origin: border-box;/*从border-box开始进行剪辑*/
        }
    </style>s
</head>
<body>
    <div id="example1"></div>
</body>
</html>

边框样式

常用的边框样式
border 边框线类型
border-radius

圆角边框——border-radius 属性。

单位 描述
length 定义圆角的形状。(圆角半径)
% 比百分比定义圆角的形状
border-radius

如果要绘制的圆角边框4个角的半径各不相同时,需按左上角、右上角、右下角、左下角的顺序设置每个方向圆角半径的值。

div{
    border-top-left-radius: 0px;
    border-top-right-radius: 10px;
    border-bottom-right-radius: 20px;
    border-bottom-left-radius: 30px;
    /*上述的四句代码等同于:border-radius:0px 10px 20px 30px;*/
}
border-image

图像边框——border-image 属性

ABCD四个参数表示浏览器自动把图像分隔时的上边距、右边距、下边距以及左边距。

border-image

border-image 属性是一个简写属性,用于设置以下属性:

描述
border-image-source 定义用在边框的图片的路径
border-image-slice 定义如何裁切背景图像
border-image-width 图片边框的宽度
border-image-outset 边框图像区域超出边框的量
border-image-repeat 图像边框是否应平铺(repeated)、铺满(rounded)或拉伸(stretched)

阴影

向框添加一个或多个阴影——box-shadow 属性

语法:box-shadow: h-shadow v-shadow blur spread color inset;

border-shadow border-shadow
上一篇 下一篇

猜你喜欢

热点阅读