css写网页盒模型用最简单最经典布局(盒子里上面是图片,下面是文字)

css写网页盒模型用最简单最经典布局(盒子里上面是图片,下面是文字)

*⚠️ magin:0 auto;和text-aligin:center;在设置子元素定位会发生结果紊乱
以下为测试代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 600px;
            height: 600px;
            background: skyblue;
            margin: 0px auto;
            /* overflow: hidden; */
            position: relative;
            /* text-align: center; */
        }
        /* .box1{
            width: 600px;   
            height: 100px; 
            background: pink;
            margin: 0px auto; 
        } */
        span{
            display: block;
            /* margin: 0 auto; */
            width: 100%; 
            text-align: center;
            /* width: 140px; */
            height: 20px;
            line-height: 20px;
            font-size: 20px;
            color: red;
            position: absolute;
            background-color: blue;
            /* margin-bottom: 0; */
            bottom: 0;
            /* left: 50%;
            margin-left: -70px; */
            /* margin-left: 50px; */
        }
        img{
            /* position: absolute; */
            display: block;
            width: 150px;
            height: 150px;
            /* right: 0; */
            /* display: inline-block; */
            /* display: inline; */
            /* bottom: 0; */
            margin:0 auto;
        }
    </style>
</head>
<body>
    <div class="box">
        <span>你懂的点点滴滴</span>
        <img src="https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=2589349710,30522182&fm=173&app=49&f=JPEG?w=312&h=208&s=49518B44457E81DE5EE8340F000080C2" alt="">

</div>
<div class="box1"></div>
</body>
</html>

输出结果如下所示
**如图所示**

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值