我写了两个div包裹一些a标签,两个div都是绝对定位,然后浮动就不生效了
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>absolute float</title>
<style>
.box1 {
position: absolute;
}
.box2 {
background-color: #bfa;
position: absolute;
}
.box2 a {
width: 10px;
height: 10px;
border-radius: 50%;
background-color: #00f;
float: left;
}
</style>
</head>
<body>
<div class="box1">
<div class="box2">
<a href=""></a>
<a href=""></a>
<a href=""></a>
</div>
</div>
</body>
</html>
就是想知道为什么float失效了。
并没有失效,是因为你的父元素没有设置宽度,看不出来。float是移动到所处容器的边框,可以看下定义。所以你这里浮动元素的容器是box2。复制以下代码就能看到效果
float