不同部分的说明:
CSS盒子模型是网页布局的基础,描述了元素在页面上的排列方式。一个盒子由以下四个部分组成:
width
和height
属性设置内容区域的大小,默认是和字内容区域的大小。padding
border
(复合属性)border-width
border-style
border-color
border: 50px double aqua;
border-radius: 5%;
box-shadow: 10px 10px 10px rgb;
margin
margin: auto;
width
和height
属性仅包括内容的尺寸,不包括内边距、边框和外边距。width
和height
属性包括内容的尺寸、内边距和边框,不包括外边距。box-sizing: border-box
使用IE盒模型。display: flex;
flex-direction: row | column;
flex-wrap: nowrap | wrap;
justify-content: flex-start | flex-end | center | space-between | space-around;
align-items: flex-start | flex-end | center | baseline | stretch;
float
属性,实现元素的水平排列。position
属性,实现元素的定位。display
属性为flex
,实现垂直和水平方向上的布局。html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>盒子模型</title>
<style>
div {
width: 200px;
height: 200px;
background-color: aquamarine;
}
</style>
</head>
<body>
<div>这里是内容</div>
</body>
</html>
html<style>
div {
padding: 50px;
}
</style>
html<style>
.A {
width: 250px;
height: 300px;
background-color: aquamarine;
border: 10px double aqua;
border-radius: 50px;
box-shadow: 10px 10px 10px grey;
}
</style>
html<style>
div {
margin: 20px;
}
</style>
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
.flex-container {
display: flex;
justify-content: center;
align-items: center;
height: 300px;
background-color: #f0f0f0;
}
.flex-item {
padding: 20px;
border: 1px solid #333;
background-color: #ffffff;
}
</style>
</head>
<body>
<div class="flex-container">
<div class="flex-item">这是一个弹性子项</div>
<div class="flex-item" style="width: 200px;">另一个弹性子项</div>
</div>
</body>
</html>
这个总结涵盖了CSS盒子模型的基本概念、组成部分、类型、布局应用以及注意事项,并提供了一些示例代码。
本文作者:空白格
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!