浮动有关问题
浮动问题

<style>
div {
width:100px;
height:100px;
}
#d1{
background-color:red;
float:left;
}
#d2{
background-color:yellow;
}
</style>
</head>
<body>
<div id="d1">左浮动</div>
<div id="d2">相对定位</div>
</body>
为什么"相对定位"这个文本要显示在d1下面
------解决思路----------------------
d2也设置浮动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<style type="text/css">
div {
width:100px;
height:100px;
}
#d1 {
background-color:red;
float:left;
}
#d2 {
background-color:yellow;
float:left;
}
</style>
</head>
<body>
<div id="d1">左浮动</div>
<div id="d2">相对定位</div>
</body>
</html>
<style>
div {
width:100px;
height:100px;
}
#d1{
background-color:red;
float:left;
}
#d2{
background-color:yellow;
}
</style>
</head>
<body>
<div id="d1">左浮动</div>
<div id="d2">相对定位</div>
</body>
为什么"相对定位"这个文本要显示在d1下面
------解决思路----------------------
d2也设置浮动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<style type="text/css">
div {
width:100px;
height:100px;
}
#d1 {
background-color:red;
float:left;
}
#d2 {
background-color:yellow;
float:left;
}
</style>
</head>
<body>
<div id="d1">左浮动</div>
<div id="d2">相对定位</div>
</body>
</html>