html - div 内表格 float 溢出

标签 html css css-float

我想知道为什么放入 divtable 元素在具有 float:right 属性的情况下会超出它的边界?

<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为了清楚起见

我希望表格应该放在边界区域内,同时漂浮在它的右侧。

最佳答案

当然可以。如果您希望它们在一行中,您只需将右浮动元素放在 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>

关于html - div 内表格 float 溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27675135/

相关文章:

css - 文本溢出隐藏中断 float

CSS - 在容器 div 内使 3 个 div float 并居中的问题..(包含代码和粗略图表)

jquery scrollto + addclass 到 div

html - 如何将页脚保持在页面底部?

html - 如何在复制时排除部分文本

javascript - 使用 Typedjs 在每个字符处播放声音

css - 如何使用 float :left property in CSS without having the trouble I have?

html - 将表头与 Firefox 中的其他表体对齐

php - 滚动时如何使表格不越位?

javascript - 当 Javascript 仅为特殊视口(viewport)构建时,我如何实现它?