<!DOCTYPE html>
<
html
lang=
"en">
<
head>
<
meta
charset=
"UTF-8">
<
meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0">
<
meta
http-equiv=
"X-UA-Compatible"
content=
"ie=edge">
<
title>Document</
title>
<
style>
.far {
border:
1
px
solid
#ccc;
}
.son {
width:
200
px;
height:
200
px;
background:
#49ff00;
}
</
style>
</
head>
<
body>
<
div
class=
"far">
<
div
class=
"son"></
div>
</
div>
</
body>
</
html>
代码显示的图形:
盒子设置浮动:
<!DOCTYPE html>
<
html
lang=
"en">
<
head>
<
meta
charset=
"UTF-8">
<
meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0">
<
meta
http-equiv=
"X-UA-Compatible"
content=
"ie=edge">
<
title>Document</
title>
<
style>
.far {
border:
1
px
solid
rgb(
8,
8,
8);
}
.son {
width:
200
px;
height:
200
px;
background:
#49ff00;
/* 子盒子设置浮动 */
float:
left;
}
</
style>
</
head>
<
body>
<
div
class=
"far">
<
div
class=
"son"></
div>
</
div>
</
body>
</
html>
代码显示的图形:
盒子设置浮动后 下面页面布局:
<!DOCTYPE html>
<
html
lang=
"en">
<
head>
<
meta
charset=
"UTF-8">
<
meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0">
<
meta
http-equiv=
"X-UA-Compatible"
content=
"ie=edge">
<
title>Document</
title>
<
style>
.far {
border:
1
px
solid
#ccc;
}
.son {
width:
200
px;
height:
200
px;
/* 子盒子设置浮动 */
float:
left;
background:
#49ff00;
}
.bod {
width:
600
px;
height:
400
px;
background:
#0094ff;
}
</
style>
</
head>
<
body>
<
div
class=
"far">
<
div
class=
"son"></
div>
</
div>
<
div
class=
"bod"></
div>
</
body>
</
html>