关于背景图片

背景图:
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>背景图</title>
    <style type="text/css">
        body ,html { padding: 0px;margin: 0px;}
        body {
            background-image: url("images/0.png");
        }
        .main {
            width: 80%;
            height: 100px;
            margin: 0 auto;
            border: 1px solid #ffff00;
        }
    </style>
</head>
<body>
    <div class="main">
        内容在背景图片上。
    </div>
</body>
</html>
还有控制背景图片的属性:
background-position: top center  ;/*向上对齐,左右居中*/
background-repeat: no-repeat;/*平铺与否*/

background-size:contain;/*可参见http://www.w3school.com.cn/cssref/pr_background-size.asp*/

img标签做:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>背景变img图</title>
    <style type="text/css">
        body {padding: 0px; margin: 0px;}
        .mainBody {
            width: 100%;
        }
        .divImg {
            position: absolute;
        }
        .main {
            width: 300px;
            height: 100px;
            border: 1px solid #ffff00;
            position: absolute;
            left: 20px;
            top: 10px;
        }
    </style>
</head>
<body>
    <div class="mainBody">
        <div class="divImg">
            <img src="images/0.png">
        </div>
        <div class="main">
            img作为“背景图片”。
        </div>
    </div>
</body>
</html>
设置position:absolute;定位后,脱离了文档流,要用偏移量来设置位置。
left: 20px;
top: 10px;
等价于
margin-left: 20px;
margin-top: 10px;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值