Le flottement de l'élément enfant empêchera l'ouverture de la boîte de l'élément parent, ce qui empêchera l'affichage du style de l'élément parent. Voici plusieurs méthodes pour effacer le
Code original flottant. :
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style type="text/css"> #content{ border: 1px red solid; } .fl{ border: 1px blueviolet solid; height: 100px; width: 100px; float: left; } .fr{ border: 1px green solid; height: 200px; width: 200px; float: right; } </style></head><body><p id="content"> <p class="fl">内容一</p> <p class="fr">内容二</p></p></body></html>
Affiché comme suit :
1 Définir la hauteur de l'élément parent :
height: 500px; /*设置父元素高度*/
<🎜. >
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style type="text/css"> #content{ border: 1px red solid; height: 500px; /*设置父元素高度*/ } .fl{ border: 1px blueviolet solid; height: 100px; width: 100px; float: left; } .fr{ border: 1px green solid; height: 200px; width: 200px; float: right; } </style></head><body><p id="content"> <p class="fl">内容一</p> <p class="fr">内容二</p></p></body></html>
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style type="text/css"> #content{ border: 1px red solid; position: absolute; /*父元素绝对定位*/ } .fl{ border: 1px blueviolet solid; height: 100px; width: 100px; float: left; } .fr{ border: 1px green solid; height: 200px; width: 200px; float: right; } </style></head><body><p id="content"> <p class="fl">内容一</p> <p class="fr">内容二</p></p></body></html>
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style type="text/css"> #content{ border: 1px red solid; overflow: hidden; } .fl{ border: 1px blueviolet solid; height: 100px; width: 100px; float: left; } .fr{ border: 1px green solid; height: 200px; width: 200px; float: right; } </style></head><body><p id="content"> <p class="fl">内容一</p> <p class="fr">内容二</p></p></body></html>
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style type="text/css"> #content{ border: 1px red solid; float: left; } .fl{ border: 1px blueviolet solid; height: 100px; width: 100px; float: left; } .fr{ border: 1px green solid; height: 200px; width: 200px; float: right; } </style></head><body><p id="content"> <p class="fl">内容一</p> <p class="fr">内容二</p></p></body></html>
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style type="text/css"> #content{ border: 1px red solid; } .fl{ border: 1px blueviolet solid; height: 100px; width: 100px; float: left; } .fr{ border: 1px green solid; height: 200px; width: 200px; float: right; } .clear{ clear: both; } </style></head><body><p id="content"> <p class="fl">内容一</p> <p class="fr">内容二</p> <p class="clear"></p></p></body></html>
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!