Box-sizing reset

本文深入探讨了CSS中box-sizing属性的使用,通过实例对比了border-box和content-box两种不同的盒模型,展示了它们如何影响元素的布局和尺寸计算。

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        html {
            /*为元素设定的宽度和高度决定了元素的边框盒。
            就是说,为元素指定的任何内边距和边框都将在已设定的宽度和高度内进行绘制
            通过从已设定的宽度和高度分别减去边框和内边距才能得到内容的宽度和高度。*/
            box-sizing: border-box;
        }
        *,
        *::before,
        *::after {
            box-sizing: inherit;//规定应从父元素继承 box-sizing 属性的值
        }
        .box {
            display: inline-block;
            width: 150px;
            height: 150px;
            padding: 10px;
            background: tomato;
            color: white;
            border: 10px solid red;
        }
        .content-box {
            box-sizing: content-box;//宽度和高度分别应用到元素的内容框在宽度和高度之外绘制元素的内边距和边框

        }
    </style>
</head>
<body>
<div class="box">border-box</div>
<div class="box content-box">content-box</div>
<script>
</script>
</body>
</html>

<div style="max-width: 775px; margin: 0 auto; background-color: #ffffff; overflow: hidden; box-sizing: border-box;"> <!-- 主内容区域 --> <div style="background-color: #141414; padding: 80px;padding-bottom: 106px; color: #ffffff; box-sizing: border-box;"> <!-- Logo --> <div style="margin-bottom: 48px; box-sizing: border-box;"> <img src="https://test-static.playol.com/static/imgs/header.png" alt="PlayOL Logo" style="width: 100px; height: 100px; display: block; box-sizing: border-box;"> </div> <!-- 问候语 --> <div style="font-size: 36px; margin-bottom: 36px; color: #BFBFBF; box-sizing: border-box;height: 49px;"> ${email}, Hello! </div> <!-- 邀请文本 --> <div style="font-size: 30px; font-weight: 600; margin-bottom: 8px; box-sizing: border-box;height: 49px;"> You are about to reset your PalyOL password </div> <div style="text-align: left; box-sizing: border-box;margin-bottom: 24px;"> Here is your verification code: </div> <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 32px; box-sizing: border-box;height: 49px;"> <span style="font-size: 36px; font-weight: 600; box-sizing: border-box;">${code}</span> </div> <!-- 有效期说明 --> <div style="font-size: 14px; color: #cccccc; text-align: left; line-height: 1.6; box-sizing: border-box;margin-bottom: 80px; "> The verification code is valid for 5 minutes. Do not disclose the verification code to others. If it is not my operation or you do not need to reset the password, you can ignore this email. </div> <!-- 结尾语 --> <div style="padding-left: 24px; border-left: 4px solid #FF1F1F; box-sizing: border-box;"> <div style="font-size: 16px; box-sizing: border-box;">祝您游戏愉快,</div> <div style="font-size: 16px; font-weight: 600; box-sizing: border-box;">PlayOL团队</div> </div> </div> <!-- 邮件底部 --> <div style="background-color: #ffffff; padding: 60px; padding-left: 80px; color: #000000; border-top: 1px solid #e0e0e0; box-sizing: border-box;"> <!-- 系统提示 --> <div style="font-size: 13px; margin-bottom: 20px; text-align: left; box-sizing: border-box;"> 这封电子邮件由系统自动生成,请勿回复。 </div> <!-- 游玩网址 --> <div style="text-align: left; margin-top: 34px;margin-bottom: 50px; font-size: 14px; box-sizing: border-box;"> <div style="margin-bottom: 5px; box-sizing: border-box;">游玩网址</div> <a href="https://playol.com" target="_blank" style=" text-decoration: none; box-sizing: border-box;font-size: 18px;color: #000000; ">https://playol.com</a> </div> <!-- Footer Logo --> <div style="text-align: left; margin-bottom: 24px;box-sizing: border-box;"> <div style="display: inline-flex; align-items: center; gap: 10px; box-sizing: border-box;"> <img src="https://test-static.playol.com/static/imgs/logo.png" alt="PlayOL Logo" style="width: 160px; height: 48px; box-sizing: border-box;"> </div> </div> <!-- 版权信息 --> <div style="text-align: left; font-size: 12px; line-height: 1.8; box-sizing: border-box;"> <span style="font-weight: 700;">© PalyOL Corporation. All Rights Reserved.</span><br> 保留所有权利。所有商标均为其在x国及其他国家/地区的各自持有者所有。 </div> </div> </div> 给每一行后边加\
11-04
<div style="max-width: 775px; margin: 0 auto; background-color: #ffffff; overflow: hidden; box-sizing: border-box;"> <div style="background-color: #141414; padding: 80px; padding-bottom: 80px; color: #ffffff; box-sizing: border-box; position: relative;"> <div style="margin-bottom: 48px; box-sizing: border-box;"> <img src="https://test-static.playol.com/static/imgs/header.png" alt="PlayOL Logo" style="width: 100px; height: 100px; display: block; box-sizing: border-box;"> </div> <div style="font-size: 36px; font-weight: 600; margin-bottom: 36px; color: #BFBFBF; box-sizing: border-box; line-height: 1.362; height: 49px;"> ${email}, Hello! </div> <div style="font-size: 29px; font-weight: 600; margin-bottom: 36px; color: #FFFFFF; box-sizing: border-box; line-height: 1.362; height: 80px;"> You are about to reset your PalyOL password,<br> Here is your verification code </div> <div style="font-size: 36px; font-weight: 600; margin-bottom: 24px; color: #FFFFFF; box-sizing: border-box; line-height: 1.362; height: 49px;"> ${code} </div> <div style="font-size: 14px; font-weight: 400; color: #FFFFFF; text-align: left; line-height: 1.362; box-sizing: border-box; margin-bottom: 80px; height: 19px;"> The verification code is valid for 5 minutes. Do not disclose the verification code to others. If it is not my operation or you do not need to reset the password, you can ignore this email. </div> <div style="padding-left: 24px; border-left: 4px solid #FF1F1F; box-sizing: border-box; height: 80px; display: flex;flex-direction: column;justify-content: center;"> <div style="font-size: 14px; box-sizing: border-box;">Have fun playing!</div> <div style="font-size: 14px; font-weight: 600; box-sizing: border-box;">The PlayOL Team</div> </div> </div> <div style="background-color: #ffffff; padding: 60px; padding-left: 80px; padding-right: 80px; color: #000000; box-sizing: border-box;"> <div style="font-size: 14px; font-weight: 400; margin-bottom: 20px; text-align: left; box-sizing: border-box; line-height: 1.4; color: #000000;"> This email was automatically generated. Please do not reply. </div> <div style="text-align: left; margin-bottom: 50px; box-sizing: border-box;"> <div style="font-size: 14px; font-weight: 400; margin-bottom: 5px; color: #000000; line-height: 1.4; box-sizing: border-box; font-family: 'PingFang SC', sans-serif;"> Play URL</div> <a href="https://playol.com" target="_blank" style="text-decoration: none; box-sizing: border-box; font-size: 18px; font-weight: 400; color: #000000; line-height: 1.4; font-family: 'PingFang SC', sans-serif;">https://playol.com</a> </div> <div style="display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; box-sizing: border-box;"> <div style="flex: 1; box-sizing: border-box;"> <div style="text-align: left; margin-bottom: 24px; box-sizing: border-box;"> <div style="display: inline-flex; align-items: center; gap: 10px; box-sizing: border-box;"> <img src="https://test-static.playol.com/static/imgs/logo.png" alt="PlayOL Logo" style="width: 160px; height: 48px; box-sizing: border-box;"> </div> </div> <div style="text-align: left; font-size: 12px; font-weight: 400; line-height: 1.4; box-sizing: border-box; color: #000000; font-family: 'PingFang SC', sans-serif;"> <div style="margin-bottom: 8px; box-sizing: border-box;"><span style="font-weight: 700;">© PalyOL Corporation. All Rights Reserved.</span></div> <div style="box-sizing: border-box;">All rights reserved. All trademarks are the property of their respective owners in the U.S. and other countries/regions.</div> </div> </div> </div> </div> </div> 每一行的末尾都加上了反斜杠 \
最新发布
11-06
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值