box-sizing: border-box

 box-sizing: border-box




INDEX.HTML:


<!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>CSS Tutorial</title>    
    <link rel="stylesheet" href="styles.css">

   
</head>
<body >
    <div class="box-1"><h1>i'm with border-box</h1></div>
    <div class="box-2"><h1>i'm normal </h1></div>
    <div class="box-3"><h1>i'm without border-box</h1></div>
</body>
</html>

CSS:
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
.box-1,.box-2,.box-3 {
    width: 200px;
    height: 200px;
}
.box-1{
    background: red;
    color: white;
    padding: 20px;
    box-sizing: border-box;
}
.box-2 {
    background: blue;
    color: white;
    padding: 20px;
}
.box-3 {
    background: green;
    color: white;
    padding: 20px;
}

评论

此博客中的热门博文

通过Graphql成功地查询Contentful,以便在我的gatsby项目中访问和显示图像

Oracle忘了保存,Oracle Cloud甲骨文云服务器忘记SSH秘钥或未设置Public key的解决办法...

国外免费虚拟主机主要搭建网站