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;
}
评论
发表评论