浮动,就是使元素脱离标准流,移动到其父元素指定的位置的过程,包括float: left float: right;
浮动常见的问题:
1.浮动的子元素无法超出父元素的范围;
<head>
<style type="text/css">
#father {
width: 200px;
height: 200px;
background-color:#f00;
}
#son {
width: 100px;
height: 100px;
background-color: #0f0;
float:right;
}
</style>
</head>
<body>
<div id="father">
<div id="son"></div>
</div>
</body>
2.如果父元素设置padding,那么子元素无法超出父元素的padding;
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style type="text/css">
#father {
width: 200px;
height: 200px;
background-color:#f00;
padding: 10px;
}
#son {
width: 100px;
height: 100px;
background-color: #0f0;
float:right;
}
</style>
</head>
<body>
<div id="father">
<div id="son"></div>
</div>
</body>