css背景

1 背景色

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 300px;
            height: 200px;
            /* background-color: pink; */
            /* background-color: #abc; */
            /* 红绿蓝三原色,a是透明度0-1 */
            background-color: rgba(0,0,0,0.5);
        }
    </style>
</head>
<body>
    <div>ahhaha</div>
</body>
</html>

2 背景图片 背景平铺 背景位置

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* background-image(bgi) 背景图 */
        /* background-image:url('图片路径') */
        div{
            width: 800px;
            height: 800px;
            background-color: pink;
            background-image: url(../2css基础/四百.png);
            /* bgr背景平铺 */
            /* 默认repeat沿xy方向平铺 */
            /* background-repeat: repeat; */
            background-repeat: no-repeat;
            /* background-repeat: repeat-x; */
            /* background-repeat: repeat-y; */

            /*bgp背景位置 background-position: 0 0; */
            /* background-position: right bottom; 右下 */
            /* background-position: 200px 200px; 像素位置 */
            /* background-position: -50px 200px; */
            /* center中间 top上面 bottom底部 */
            /* left左 right右 center中间 */
        }
    </style>
</head>
<body>
    <div>我有背景图</div>
    <p>hahahaha</p>
</body>
</html>

3 背景属性连写

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
                p{
            /* 属性连写 */
            /* 不分顺序:背景色,背景图,背景平铺,背景位置 
             背景位置是数值表示的话先写的表示水平后面的表示垂直 */
            width: 800px;
            height: 800px;
            background: green url(./四百.png) no-repeat center center;
        }
    </style>
</head>
<body>
    <p>哈哈哈</p>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值