2014-12-28 60 views
1

我不知道爲什麼要素投入超出它的邊界在情況下,它浮動:正確財產?表浮動溢出裏面的div

<div id="bordered_div"> 
<p> Some text 1 
<p> Some text 2 
<table id="myTable"> 
    <tr> 
     <td>Row11</td> 
     <td>Row12</td> 
    </tr> 
    <tr> 
     <td>Row22</td> 
     <td>Row21</td>    
    </tr>   
</table> 
<div> 

#bordered_div { 
    border: 1px solid #8c8c8c 
} 

#myTable { 
    float: right; 
    border: 1px solid #8c8c8c; 
    margin-bottom: 10px; 
    margin-left: 10px; 
} 

請參閱jsFiddle爲清楚起見

我期望表應該是同時在其右側浮起的邊界區域內的地方。

回答

0

你當然可以做到。如果你希望它們在一行中,你只需要在float:none元素之前放置右浮動元素。因此,表前應段落去

#bordered_div { 
 
    border: 1px solid #8c8c8c 
 
} 
 

 
#myTable { 
 
    float: right; 
 
    border: 1px solid #8c8c8c; 
 
    margin-bottom: 10px; 
 
    margin-left: 10px; 
 
}
<div id="bordered_div"> 
 
    <table id="myTable"> 
 
     <tr> 
 
      <td>Row11</td> 
 
      <td>Row12</td> 
 
     </tr> 
 
     <tr> 
 
      <td>Row22</td> 
 
      <td>Row21</td>    
 
     </tr>   
 
    </table> 
 
    <p> Some text 1 
 
    <p> Some text 2 
 
<div>

+0

嗯,是的,但這不是預期的結果佈局。我希望我的表格可以放在*段落之後,然後飄到右邊。那可能嗎? –

+0

那麼* expected *結果就是浮動元素不能被渲染得高於之前的塊級元素('p')。需要考慮可能的技巧.. – dfsq