javascript - 如何更改表内元素的顺序?

标签 javascript jquery html css

Demo

我将此表与 css-trick 一起使用响应表的解决方案。现在我还想做的是在表格更改后更改元素的顺序 (768px),以便 <h3>和图像更改顺序,因此它将是 1. 标题,2. 图片,3. 文本。

我该怎么做?

这是我目前所拥有的

<table border="0">
    <tbody>
        <tr>
            <td class="aimg">
                <img src="#">
            </td>
            <td class="atext">

<h3>Title 1</h3>

                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
            </td>
        </tr>
        <tr>
            <td class="aimg">
                <img src="#">
            </td>
            <td class="atext">

<h3>Title2</h3>

                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
            </td>
        </tr>
    </tbody>
</table>

CSS

.actions table td {
    vertical-align: top;
}
.actions table td.aimg {
    width:175px;
    padding-bottom:20px;
}
.actions table td.atext {
    padding-left:20px;
}

@media only screen and (max-width: 760px), (min-device-width: 768px) and (max-device-width: 1024px) {
    /* Force table to not be like tables anymore */
    .actions table, thead, tbody, th, td, tr {
        display: block;
    }
    .actions table tr {
        border-bottom:1px dashed #c0c7c7;
        margin-bottom:20px;
    }
    .actions table td.aoptions {
        padding-left:0px;
    }
}

最佳答案

Fiddle

由于表格标记,这有点棘手。 基本上,你给 tr 这个 css:

position: relative;

然后将标题绝对定位在左上角,并根据标题的高度为图像提供适当的顶部填充。

对此可能有更好、更灵活的解决方案。

还有...为什么要对一个显然不是表格的元素使用表格标记?

关于javascript - 如何更改表内元素的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22253153/

相关文章:

javascript - 悬停后检查新的悬停目标(Javascript/JQuery)?

javascript - 您可以从谷歌地图中删除竞争对手列表吗?

jquery - 使用JQuery通过div轮播

jquery - 有一个滚动表,想从滚动的底部开始吗?

javascript - Node 模块对象范围: share an object across all functions

javascript - Pikaday 在多个字段上多个触发器

javascript - 将 <div> 从一个 <div> 来回移动到另一个

jquery - 缩放 Div/iframe 内的文本大小

html - IE 的菜单 CSS 问题

javascript - jquery 克隆日期选择器不工作