html div重叠问题,原因分析和处理

时间:2023-03-10 04:43:50
html div重叠问题,原因分析和处理

1、现象

<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>重叠DIV</title>
<style>
.left{width:200px; float:left; color:#F00; border:1px solid #F00}
.nofloat{width:100px; background:#CCC}
</style>
</head>
<body>
<div class="left">left对象DIV内</div>
<div class="nofloat">nofloat对象DIV内</div>
</body>
</html>

  html div重叠问题,原因分析和处理

2原因分析

class=left的div盒子使用了浮动属性float:left,而class=nofloat未使用。这样一个浮动DIV,一个未使用float浮动属性,所以就造成重叠现象。

3、解决方法

(1)清除样式

(2)2个都用浮动,或者都不用。