使用 CSS3 创建带有 Box-Sizing 的布局
cssweb developmentfront end technology更新于 2025/11/27 16:12:17
要使用 CSS3 创建带有 Box-Sizing 的布局,代码如下 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
body{
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
.container{
width: 500px;
border:8px solid rgb(35, 0, 100);
}
.border {
box-sizing: border-box;
width: 100%;
height: 100px;
border: 4px solid rgb(4, 97, 54);
}
.content {
width: 100%;
height: 100px;
padding: 50px;
border: 4px solid rgb(255, 0, 191);
box-sizing: content-box;
}
</style>
</head>
<body>
<h1>Box sizing layout example</h1>
<div class="container">
<div class="border">This div has 100% width and box-sizing property set to border
box</div>
<br>
<div class="content">This div also has 100% width but has the box-sizing property set to
content box</div>
</div>
</body>
</html>
输出
上述代码将产生以下输出 −

相关文章
有用资源
css 参考教程 - 该教程包含有关 css 的更多信息:https://www.cainiaomax.com/css/

