为了账号安全,请及时绑定邮箱和手机立即绑定

急求CSS的浮动问题

急求CSS的浮动问题

<html> <head> <style type="text/css"> *{ padding:0px; margin:0px;} #king{ border:1px solid #f00; width:200px; height:200px; margin-left:100px; margin-top:100px;} #a{ border:1px solid #00f; width:100px;} div.a_son{ float:left; border:1px solid #063; width:40px; height:40px;} #b{ float:left; border:1px solid #0F0; width:100px; height:100px;} #queen{ border:1px solid #f00; width:200px; height:200px;} #e{ float:left; border:1px solid #00f; width:50px; height:50px; margin-top:20px;} #f{ float:left; border:1px solid #00f; width:50px; height:50px;} </style> </head> <body> <div id="king"> <div id="a"  class="crearfix">      <div class="a_son"></div>         <div class="a_son"></div>         <div class="a_son"></div>         <div class="a_son"></div>     </div>     <div id="b"></div> </div> </body> </html>运行之后是这样的:我想问下为什么b框与父级框顶端有一定距离啊,这是为什么????
查看完整描述

1 回答

?
qq_Miss丶不曾忘记_0

TA贡献2条经验 获得超0个赞

<html>
<head>
<style type="text/css">
    *{ padding:0px; margin:0px;}
    #king{ border:2px solid blue; width:300px; height:200px; margin-left:100px; margin-top:100px;}
    #a{float:left; border:1px solid red; width:100px }
    div.a_son{ float:left; border:1px solid black; width:40px; height:40px;}
    #b{ float:left; border:1px solid #0F0; width:100px; height:100px;}
     
    #queen{ border:1px solid #f00; width:200px; height:200px;}
    #e{ float:left; border:1px solid #00f; width:50px; height:50px; margin-top:20px;}
    #f{ float:left; border:1px solid #00f; width:50px; height:50px;}
</style>
</head>
<body>
<div id="king">
    <div id="a"  >
        <div class="a_son"></div>
        <div class="a_son"></div>
        <div class="a_son"></div>
        <div class="a_son"></div>
    </div>
    <div id="b"></div>
</div>
</body>

上面是改后代码,

你的#a没有设置高,可能是你故意的。不过建议设置上,那样看起来效果明显点。

之所以#b和父框#king有距离是因为你的#a没有设置 float:left;


查看完整回答
反对 回复 2015-09-05
  • 或君子或小人
    或君子或小人
    我没设置#a的高度,此时如果#b没设置float的话,#b是肯定忽略#a中的子框而顶到#a的下边缘的,再为#b设置float后,照道理说#b应该顶着#a的下边缘飘到#a四个子框的后面的啊,怎么会平白无故往下移了一个子框高度的距离呢?
  • 1 回答
  • 0 关注
  • 1376 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信