Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
css将div向右与at table对齐,在右侧100%_Css_Html_Css Float_Alignment - Fatal编程技术网

css将div向右与at table对齐,在右侧100%

css将div向右与at table对齐,在右侧100%,css,html,css-float,alignment,Css,Html,Css Float,Alignment,我有一张100%宽的桌子。我会添加一个随机的div与php的广告充分的时间。我希望广告部门在右边,表格的内容。我希望表格在左边,但仍然是100%左右,它将填充ad div左边的所有空间 简而言之,当div不存在时,表格将填充100%的宽度。 当div存在时,div将位于桌子的右侧,设置宽度为300px 这是div的风格 .ContentAds { float: right; height: 100%; width: 300px; display: block;

我有一张100%宽的桌子。我会添加一个随机的div与php的广告充分的时间。我希望广告部门在右边,表格的内容。我希望表格在左边,但仍然是100%左右,它将填充ad div左边的所有空间

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

这是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>

标题

这就是内容。这就是内容。这就是内容。这就是内容。这就是内容。这就是内容。这就是内容。这就是内容


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


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

现在,我只能建议您使用定位DIV包装表。但是我不能确定这是否足以满足您的需要,因为您提供了相当少的代码


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

这是什么意思
我希望ad div位于右侧以及表格的内容。
?另外,您到底想要什么:
表格位于左侧,但仍为100%
或div设置为300px的
,如果div不存在,表格将为100%。如果存在,则它将以300px的速度位于左侧,表内容将位于div的左侧,但会填充整个空间。有意义吗?如果表将延伸到100%宽度,并且具有与div相同的父级,那么将没有放置div的位置,因为父级的宽度为100%,您需要100%+300px。但我相信有一些解决办法,你只需要澄清你的任务就行了。我当时所说的100%是指填满页面的左侧。。。所有这些。所以,也许还有70%的空间,但我希望表格能填满左边100%的空间。您需要动态切换表的css类,或者可能是id。所以,当您发送到客户端时,不带div的html表将具有100%的宽度,而带div时,您将提供另一种样式
<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>
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;
}