CSS盒模型和盒子的实际宽度

 但凡是块元素  都可以认为是盒子 

        /* 盒子身上有5大属性 */

        /* 一个盒子中主要的属性就5个:width、height、padding、border、margin */

​
<style>
    .box{
            /* 内容的宽度 */
            width: 300px;
             /* 内容的高度 */
            height: 300px;
            /* 内边距  padding属性后面值的书写顺序:上内边距 右内边距 下内边距 左内边距 (上 右 下 左*/
            padding: 20px 20px 20px 20px;
           /* 边框 
           1opx   边框粗细
           solid     实线
           skyblue    边框颜色  */
            /* border: 10px solid skyblue; */
            border-top: 50px solid blue;
            border-right: 10px solid yellowgreen;
            border-bottom: 50px solid yellow;
            border-left: 50px solid pink;
            /* 外边距 (上右下左)*/
            margin: 0 0 60px 0;
            }
    </style>
</head>
<body>
    <!-- div是块元素 -->
   <div class="box">
    <img src="./img/1.webp" alt="" width="300" height="300">
   </div> 


   <div class="box">
    <img src="./img/1.webp" alt="" width="300" height="300">
   </div> 
</body>

​

效果图:

盒子的实际宽度:

真实占有宽度= 左border + 左padding + width + 右padding + 右border

<style>
        .box1{
            width: 400px;
            height: 400px;
            border: 1px solid yellow;
        }
        .box2{
            width: 200px;
            height: 200px;
           padding: 95px;
           border: 6px solid blue;
        }
        .box3{
            width: 0;
            height: 0;
            padding: 200px;
            border: 1px solid pink;
        }
    </style>
</head>
<body>
    <!-- 三种不同的方式,创建3个一样大的盒子(这里说的一样大,是指盒子在浏览器中实际占有宽度) -->
    <div class="box1">第1个盒子</div>
    <div class="box2">第2个盒子</div>
    <div class="box3">第3个盒子</div> 
</body>

 效果图:

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值