我有以下HTML和CSS。我想知道为什么第二个框不漂浮在第一个框的侧面。据我了解,如果浮动了特定宽度的框,则其他div会浮动到浮动框/ div的左侧,直到在同一行框上没有更多的空间可容纳为止。



   #content-wrapper {
     border: 1px solid blue;
     width: 100%
   }
   .first-box {
     width: 450px;
     border: 1px solid red;
     float: left;
   }
   .first-box h2 {
     background: url(img/top-menu-bg.jpg) no-repeat;
     line-height: 45px;
     padding-left: 15px;
     margin-bottom: 15px;
   }
   .second-box {
     width: 5%;
     border: 1px solid red;
   }
   </style>

<div id="content-wrapper">
  <div class="first-box">
    <h2>Welcome to My Engg.</h2>
    <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It
      has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop
      publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
  </div>
  <div class="second-box">
    <p>Some Side bar text</p>
  </div>
</div>





谢谢

最佳答案

您需要设置display:inline-block

的CSS

#content-wrapper{
  border:1px solid blue;
  width:100%;
  display:block;
  overflow:hidden;
}

.first-box {
  width:450px;
  border:1px solid red;
  float:left;
  display:inline-block;
}

.first-box h2{
  background:url(img/top-menu-bg.jpg) no-repeat;
  line-height:45px;
  padding-left:15px;
  margin-bottom:15px;
  display:inline-block;
 }

.second-box{
  width:5%;
  border:1px solid red;
  display:inline-block; //HERE YOUR FIX
 }


DEMO HERE

10-04 16:01