html - 将图像放在表格行中

标签 html css

我在 html/css 方面很弱。

我从数据库中调用了动态数量的图像。3 图像一次显示在一行中。 这是我的表格 html/css:

<style>
    table { 
        border-collapse: collapse; 
        table-layout: fixed;
        max-width: 100%
    }
    figure {
        display: block;
        margin-before: 1em;
        margin-after: 1em;
        margin-start: 40px;
        margin-end: 40px;
    }
    figure img {
        padding: 5px;
        background: #fff;
    }
    figcaption {
        padding: 5px;
        font-family: 'Cherry Swash', cursive;
        font-size: 1em;
        font-weight: 700;
        border: none;
        background: transparent;
        word-wrap:normal;
        text-align: center;
    }
    a {
        text-decoration:none;    
    }
</style>

<table>
    <tr><td align='left'>
        <a href="works.php" title="Click To See More Work">
            <figure>
                <img src="img/11.jpg"  alt="Picture 2" title="Picture 2">
                <figcaption>
                    project name 
                    <br> Sitting stick figures hunched over their laptops! 
                    See <a href="#">more</a>.
                </figcaption>
            </figure>
        </a>
    </td></tr>
</table>

我的要求是当第四张图片被调用时,它应该自动落在下一行。请建议如何去做。有没有其他方法可以更好地做我正在做的事情。

最佳答案

最简单的方法是使用服务器端语言。 如果你使用 PHP,你可以这样做

    <table>
    <tr>
    <?php for(int i=0; i<number_of_images; i++){ ?>
       <td align='left'>
        <a href="works.php" title="Click To See More Work">
        <figure>
            <img src="img/11.jpg"  alt="Picture 2" title="Picture 2">
            <figcaption>
                project name<br>Sitting stick figures hunched over their laptops! See <a href="#">more</a>.
            </figcaption>
        </figure>
        </a>
    </td>
    <?php 
         if(i%3 == 0){ echo "</tr><tr>";}
    }
    ?>
    </tr>
    </table>

关于html - 将图像放在表格行中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15287955/

相关文章:

javascript - 在 jQuery 中使用 $ ('body' ).html ('' ) 是什么意思?

javascript - 如何强制完全加载 html5 视频?

javascript - 避免使用 javascript-jquery 代码显示级联 div

jquery - Nivo slider 将图像向下推

html - 一个关于溢出 :hidden 的简单 css 问题

css - 如何使用页面中心作为引用来对齐 div 元素?

javascript - 将鼠标悬停在类 "thing"、 "bn1"、 "bn2"等上时编辑类 "bn3"的 css?

html - 如何消除与位置 :relative banner 的差距

javascript - 如何设置最大高度并允许使用 jQueryUI Selectmenu 滚动

javascript - R Shiny : how to reduce the font size of menu sub-item in sidebar