0

我有一个设置为 100% 宽度的表格。我有时会添加一个带有 php 广告的随机 div。我希望广告 div 位于右侧和表格的内容中。我希望表格位于左侧,但仍处于 100% 左右,它将填充广告 div 左侧的所有空间。

简而言之,所以当 div 不存在时,表格将填充 100% 宽度。当 div 存在时,div 将位于表格的右侧,设置宽度为 300 像素。

这是 div 的样式

.ContentAds {
    float: right;
    height: 100%;
    width: 300px;
    display: block;
    clear: none;
}

该表不是一个 div,而是简单地设置为 100% 宽度。

<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
  <tr>
    <td><p class="Title">Title</p>
    <p>This is the content. This is the content. This is the content. This is the content. This is the content. This is the content. This is the content. This is the content.. </p></td>
  </tr>
</table>
4

2 回答 2

2

现在我只能建议用定位的 div 包裹你的桌子。但我不能确定这对你来说是否足够,因为你提供了相当少量的代码 jsfiddle

<div class="ad">
    advertise... advertise
    advertise... advertise
    advertise... advertise
</div>
<div class="table_wr">
    <table>
        <tr>
            <td>
                <p class="Title">Title</p>
                <p>
                    This is the content. This is the content.
                    This is the content. This is the content.
                    This is the content. This is the content.
                    This is the content. This is the content..
                </p>
            </td>
        </tr>
    </table>
</div>

CSS

body {
    position: relative;
}
table {
    border: 1px solid black;
    width: 100%;
}
.ad {
    float:right;
    width:300px;
    height: 500px;
    background-color: #a2e89f;
}
.table_wr {
    position: absolute;
    left: 0;
    right: 300px;
}

为表格设置了边框,您可以看到表格的延伸位置

于 2012-08-16T21:43:23.080 回答
0

我认为这行不通,除非您在另一个 DIV 存在时为表格设置较小的设置宽度,然后您也可以将其浮动到左侧。

也许您可以将表格设置为 100%,然后当另一个 DIV 存在时,您可以在表格上添加一个类来调整宽度并使其浮动?

于 2012-08-16T21:20:34.690 回答