开发者

100% width table row half way down a table

开发者 https://www.devze.com 2023-03-08 06:00 出处:网络
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:

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>
    <开发者_Go百科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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消