如何使文本环绕表格,就好像它是一个图像

时间:2012-05-20 02:33:18

标签: html css tabular

我很惊讶我无法找到解决方案。我想在我的文档顶部附近放置一个小桌子(1行,3个单元格),右边对齐,并用一个环绕着它的段落,就像使用以下代码的图像一样...

    <img src="http://www.sorenwagner.ws/marty/img/ca-seal.jpg"
        align="right" width="300" height="100">
    This is a paragraph large enough to wrap around the image...
    This is a paragraph large enough to wrap around the image...
    This is a paragraph large enough to wrap around the image...
    This is a paragraph large enough to wrap around the image...

能够在桌子周围定义填充也很好,因此文本不是正确的边界。在CSS中有一个相对简单的解决方案吗?

3 个答案:

答案 0 :(得分:5)

只需float右边的表格(也就是你应该如何定位图像):

<table style="float: right">
    <!-- ... -->
</table>
<p>Bunch of text...</p>

演示:http://jsfiddle.net/ambiguous/ZLfg7/1/

答案 1 :(得分:4)

jsFiddle

table {
    float: right; /* floats the table to the right,
                     allowing text to wrap around it */
    margin: 12px; /* adds buffer space around the table */
}

答案 2 :(得分:3)

将表格浮动并通过CSS给它一个边距:

table {
    float:right;
    width:300px;
    margin:0 0 10px 10px;
}​

<强> jsFiddle example