并排div显示不正确的边框底部

时间:2015-12-24 07:20:44

标签: html css

这是我的代码:

<!DOCTYPE html>
<html>

<head>
  <style>
  </style>
</head>

<body>

  <div style="border-bottom:1px solid black">
    <div style="width=50%;float:left">A paragraph with no margins specified
      <br>
      <br>A paragraph with a 2cm left margin.</div>
    <div style="width=50%;margin-left=51%">A paragraph with no margins specified.</div>
  </div>

</body>

</html>

我想在外部div的底部显示边框,但边框始终显示在第一个内部div之后。边框的代码是错误的吗?

2 个答案:

答案 0 :(得分:0)

从顶部div中删除float: left。它的罪魁祸首

答案 1 :(得分:0)

如果您需要保留浮点数,则可以将父div的overflow属性更改为auto

&#13;
&#13;
  <div style="border-bottom:1px solid black; overflow:auto;">
    <div style="width=50%;float:left">A paragraph with no margins specified
      <br>
      <br>A paragraph with a 2cm left margin.</div>
    <div style="width=50%;margin-left=51%">A paragraph with no margins specified.</div>
  </div>
&#13;
&#13;
&#13;