100% 宽度的表格行位于表格中间
我网站上的索引页面显示了我的用户最近提交的内容。它使用 HTML 表作为标记,并使用 PHP 生成。 tr 标记如下所示:
<tr>
<td class="preview"><img alt="Minecraft skin preview" src="link"></td>
<td class="skin">
<span class="title"><a href="link">Skin Edit preview broken but I did my best</a></span><br />
<span class="desc">Seraphinite Hunter</span>
</td>
<td class="auth">MikeSilver</td>
<td class="time">23-5-2011</td>
<td class="links">
<a target="_blank" href="link">Download</a><br>
<a target="_blank" href="link">Remote</a>
</td>
</tr>
我想要的是将 AdSense 广告显示在表格下方大约一半的位置。为此,我将 tr 元素的数量减半并将数字向下舍入,然后在 PHP 代码中使用计数器来检测在何处放置 AdSense 代码。问题是,当我这样做时,桌子会破裂。
我正在做这样的事情:
<?php $limit = floor($site['skinsPerPage'] / 2); $counter = 0; ?>
<?php foreach($skins as $skin): ?>
<?php if($counter == $limit): ?>
<tr>
<td>
<!-- adsense code -->
</td>
</tr>
<?php else: ?>
<!-- normal table code (as above) -->
<?php endif; ?>
<?php $counter++; ?>
<?php endforeach; ?>
有谁知道我可以用来在表格中间居中的表格单元格中显示此 AdSense 广告的正确样式吗?无论我做什么,它似乎都会破坏表格,并将表格的所有其他 td 元素推到一侧。
The index page on my site shows the most recent submissions from my users. It uses a HTML table as markup, and is generated using PHP. The tr markup looks like this:
<tr>
<td class="preview"><img alt="Minecraft skin preview" src="link"></td>
<td class="skin">
<span class="title"><a href="link">Skin Edit preview broken but I did my best</a></span><br />
<span class="desc">Seraphinite Hunter</span>
</td>
<td class="auth">MikeSilver</td>
<td class="time">23-5-2011</td>
<td class="links">
<a target="_blank" href="link">Download</a><br>
<a target="_blank" href="link">Remote</a>
</td>
</tr>
What I want is to have an AdSense ad displayed approx half way down the table. To do this, I halved the number of tr elements and rounded the number down, and then I'm using a counter in my PHP code to detect where to put in my AdSense code. Thing is, when I do this, the table breaks.
I was doing something like this:
<?php $limit = floor($site['skinsPerPage'] / 2); $counter = 0; ?>
<?php foreach($skins as $skin): ?>
<?php if($counter == $limit): ?>
<tr>
<td>
<!-- adsense code -->
</td>
</tr>
<?php else: ?>
<!-- normal table code (as above) -->
<?php endif; ?>
<?php $counter++; ?>
<?php endforeach; ?>
Does anyone know the proper styling I can use to display this AdSense ad in a table cell centered in the middle of my table? It seems to break the table whatever I do, and push all the other td
elements of the table off to one side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的
转换为
(或者您的表格有多少列)。
您实际上是将一个巨大而宽的元素推入表格的第一列。使用
colspan
允许表格单元格使用多列。Turn your
<td>
into<td colspan="6">
(or however many columns your table has).You are essentially shoving a huge, wide element into the first column of the table. Using
colspan
allows the table cell to use more than one column.