html - 如何使用响应 View 使 td 右对齐到顶部?

标签 html css html-table

我的表格与右侧的主标题对齐。

<table style="height: 233px;" width="862">
  <tbody>
    <tr>
      <td>3 ليالي و4 أيام</td>
      <td class="need-this-on-top">
        <h2><strong>المدة </strong></h2>
      </td>
    </tr>
    <tr>
      <td>تيكادي , آليبي , كوشين</td>
      <td class="need-this-on-top">
        <h2><strong>اماكن للزيارة</strong></h2>
      </td>
    </tr>
  </tbody>
</table>

移动 View

enter image description here

我需要顶部的粗体文本作为移动 View 的标题。我怎样才能用 css 做到这一点? 我已经尝试过以下代码:

显示:表头组;

有什么建议吗?

最佳答案

将 flexbox 与 flex-direction: column 结合使用并更改顺序

@media screen and (max-width: 767px) {
  .td-stacked-reversed-mobile tr {
    display: flex;
    flex-direction: column;
  }
  .td-stacked-reversed-mobile tr>td:nth-child(1) {
    order: 2;
  }
  .td-stacked-reversed-mobile tr>td:nth-child(2) {
    order: 1;
  }
}
<!-- Added class 'td-stacked-reversed-mobile' -->
<table class="td-stacked-reversed-mobile" style="height: 233px;" width="862">
  <tbody>
    <tr>
      <td>3 ليالي و4 أيام</td>
      <td class="need-this-on-top">
        <h2><strong>المدة </strong></h2>
      </td>
    </tr>
    <tr>
      <td>تيكادي , آليبي , كوشين</td>
      <td class="need-this-on-top">
        <h2><strong>اماكن للزيارة</strong></h2>
      </td>
    </tr>
  </tbody>
</table>

关于html - 如何使用响应 View 使 td 右对齐到顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51336359/

相关文章:

css - 绝对可靠的固定 TD 宽度?

java - 无法从selenium java中的ui li元素中进行选择

javascript - 如果点击取消按钮,如何拒绝输入框中的任何更改?

css - 显示 :inline-block not centering vertically in Chrome

html - 在使用不透明度和可见性属性时,如何让 child 遵循与 parent 相同的行为?

html - 如何居中2个 float div的内容

html - IE 中的表格布局错误(7)

html - 选定行,更改第一个和最后一个单元格边框

c# - @Html.Raw 在 MVC 4 中

javascript - 如何对表 dc.datatable 中的行进行颜色编码?