【问题标题】:Re-order of colums of a table on a website网站上表格列的重新排序
【发布时间】:2020-02-28 19:46:03
【问题描述】:

我已经建立了一个会议网站:http://www.nzbcs.org.nz/index.html

但我不知道如何使它在移动设备上以不同的顺序显示,即首先是中心列,然后是左右列。

非常感谢任何帮助。

下面是 index.html 中的@media 代码。 “sites36f3.css”中有 159 个@media 条目。

@media screen and (min-width: 767px) {
    .wsite-elements.wsite-not-footer:not(.wsite-header-elements) div.paragraph,
    .wsite-elements.wsite-not-footer:not(.wsite-header-elements) p,
    .wsite-elements.wsite-not-footer:not(.wsite-header-elements) .product-block .product-title,
    .wsite-elements.wsite-not-footer:not(.wsite-header-elements) .product-description,
    .wsite-elements.wsite-not-footer:not(.wsite-header-elements) .wsite-form-field label,
    .wsite-elements.wsite-not-footer:not(.wsite-header-elements) .wsite-form-field label,
    #wsite-content div.paragraph,
    #wsite-content p,
    #wsite-content .product-block .product-title,
    #wsite-content .product-description,
    #wsite-content .wsite-form-field label,
    #wsite-content .wsite-form-field label,
    .blog-sidebar div.paragraph,
    .blog-sidebar p,
    .blog-sidebar .wsite-form-field label,
    .blog-sidebar .wsite-form-field label {}
    #wsite-content div.paragraph,
    #wsite-content p,
    #wsite-content .product-block .product-title,
    #wsite-content .product-description,
    #wsite-content .wsite-form-field label,
    #wsite-content .wsite-form-field label,
    .blog-sidebar div.paragraph,
    .blog-sidebar p,
    .blog-sidebar .wsite-form-field label,
    .blog-sidebar .wsite-form-field label {}
    .wsite-elements.wsite-footer div.paragraph,
    .wsite-elements.wsite-footer p,
    .wsite-elements.wsite-footer .product-block .product-title,
    .wsite-elements.wsite-footer .product-description,
    .wsite-elements.wsite-footer .wsite-form-field label,
    .wsite-elements.wsite-footer .wsite-form-field label {}
    .wsite-elements.wsite-not-footer:not(.wsite-header-elements) h2,
    .wsite-elements.wsite-not-footer:not(.wsite-header-elements) .product-long .product-title,
    .wsite-elements.wsite-not-footer:not(.wsite-header-elements) .product-large .product-title,
    .wsite-elements.wsite-not-footer:not(.wsite-header-elements) .product-small .product-title,
    #wsite-content h2,
    #wsite-content .product-long .product-title,
    #wsite-content .product-large .product-title,
    #wsite-content .product-small .product-title,
    .blog-sidebar h2 {}
    #wsite-content h2,
    #wsite-content .product-long .product-title,
    #wsite-content .product-large .product-title,
    #wsite-content .product-small .product-title,
    .blog-sidebar h2 {}
    .wsite-elements.wsite-footer h2,
    .wsite-elements.wsite-footer .product-long .product-title,
    .wsite-elements.wsite-footer .product-large .product-title,
    .wsite-elements.wsite-footer .product-small .product-title {}
    #wsite-title {
        font-size: 30px !important;
    }
    .wsite-menu-default a {
        font-size: 13px !important;
    }
    .wsite-menu a {}
    .wsite-image div,
    .wsite-caption {}
    .galleryCaptionInnerText {}
    .fancybox-title {}
    .wslide-caption-text {}
    .wsite-phone {}
    .wsite-headline,
    .wsite-header-section .wsite-content-title {}
    .wsite-headline-paragraph,
    .wsite-header-section .paragraph {}
    .wsite-button-inner {}
    .wsite-not-footer blockquote {}
    .wsite-footer blockquote {}
    .blog-header h2 a {}
    #wsite-content h2.wsite-product-title {}
    .wsite-product .wsite-product-price a {}
}

【问题讨论】:

  • 如果您正在运行没有进行排序的后端的纯 html 页面。你可以在这里找到帮助:stackoverflow.com/questions/14267781/…
  • 这与排序无关。我知道 CSS 中“wsite-multicol-table”的修改将使中间单元格首先显示在移动设备中。不幸的是,这超出了我的范围。
  • 好的,我刚刚查看了您的网站,并解读了 .wsite-multicol-table 的含义。这是用weebly(editmysite.com)制作的,它是他们网站构建器的自定义CSS。你在说的是“页面布局”。它有一些技巧,其中之一是使用display: flex

标签: html css flexbox responsive weebly


【解决方案1】:

我已经复制了您网站的基本部分来演示。

您可以使用display: flex 对列进行重新排序,还可以为子元素设置order

下面的示例重新排列 HTML 的布局列。

您可以从这里了解更多信息:https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Ordering_Flex_Items

另外,我想通过引用上面的链接来警告:

订单属性和可访问性

使用order 属性对可访问性的影响与使用flex-direction 改变方向的含义完全相同。使用order 更改项目的绘制顺序,以及它们在视觉上出现的顺序。它不会更改项目的顺序导航顺序。因此,如果用户在项目之间切换,他们可能会发现自己以一种非常混乱的方式在您的布局中跳跃。

通过浏览此页面上的任何实时示例,您可以看到秩序如何为不使用某种指点设备的人创造一种奇怪的体验。要详细了解这种视觉顺序和逻辑顺序的脱节以及它为可访问性带来的一些潜在问题,请参阅以下资源。

.flex {
  display: flex;
}

.flex :nth-child(1) {
  order: 3;
}

.flex :nth-child(2) {
  order: 1;
}

.flex :nth-child(3) {
  order: 2;
}

.wsite-multicol-table {
  position: relative;
  border-collapse: collapse;
  table-layout: fixed;
  width: 100%;
  margin: 0 !important;
  border: 0 !important;
  padding: 0 !important;
}

tbody {
  display: table-row-group;
  vertical-align: middle;
  border-color: inherit;
}

tr {
  display: table-row;
  vertical-align: inherit;
  border-color: inherit;
}

.wsite-multicol-col {
  vertical-align: top;
  margin: 0 !important;
  border: 0 !important;
  padding: 0;
  -moz-box-sizing: border-box;
}
<table class="wsite-multicol-table">
  <tbody class="wsite-multicol-tbody">
    <tr class="wsite-multicol-tr flex">
      <td class="wsite-multicol-col" style="width:22.666666666667%;padding:0 15px;order: 10;">column 1<br>stuff</td>
      <td class="wsite-multicol-col" style="width:56.816326530612%;padding:0 15px;order: 0;">column 2<br>more stuff</td>
      <td class="wsite-multicol-col" style="width:20.517006802721%; padding:0 15px;">column 3<br>other stuff</td>
    </tr>
  </tbody>
</table>

我不确定你可以在 weebly 中编辑多少,因为我上次使用它已经 5 年多了。

此外,如果您想在移动设备上以不同方式显示,您可能需要使用 CSS 媒体查询,通常使用 @media 声明。 https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries

对于媒体查询,通常我们通过屏幕大小来控制,来源:https://stackoverflow.com/a/16443861/498031

@media only screen and (min-width: 768px) {
    /* tablets and desktop */
}

@media only screen and (max-width: 767px) {
    /* phones */
  .flex {
    ...
  }
  .flex :nth-child(n) {
    ...
  }
}

@media only screen and (max-width: 767px) and (orientation: portrait) {
    /* portrait phones */
}

【讨论】:

  • 谢谢。您可以轻松地重新排列要显示的单元格。我在响应式编码之后,让当前的中间列/单元格在第一列/单元格之前显示在移动设备中。因此,需要 CSS 媒体查询。有什么想法可以实现吗?
  • @NZBCS 如果您喜欢这个答案,请接受并投票。上面建议的解决方案是假设您可以输入自己的 CSS。 CSS 媒体查询文章链接在答案的底部。您需要做的是将查询声明为@media screen and (min-width: 900px) {.flex{...} .flex :nth-child{...} } 您必须设置最小宽度或宽度范围(例如最小宽度最大宽度)以适应移动设备的屏幕。 developer.mozilla.org/en-US/docs/Web/CSS/@media 。一个相关问题:stackoverflow.com/questions/16443380/…
  • 再次感谢您的时间和精力帮助。当前的网站已经是响应式的,并且能够根据屏幕大小调整三列(实际上是三个表格单元格#1、#2、#3)的布局。您可以通过调整台式计算机上的窗口大小来看到这一点。不幸的是,这三列以 html 中编码的顺序出现。我想要的是在屏幕尺寸减小时将布局重新排序为#2、#1 和#3,例如在移动设备中。但是,我不知道这种有条件的重新排序。
  • @NZBCS 你能编辑 CSS 或 HTML 吗?如果是这样,请在现有 CSS 中搜索适合您选择的(移动)屏幕尺寸的 @media 声明,这就是它将根据屏幕尺寸或 @media 中声明的其他属性进行条件样式设置的地方。如上插入CSS属性声明(建议在新类“.flex”中,或直接在“.wsite-multicol-tr”中,不推荐),您可以包含新类.flex,如@987654339所示@.
  • 嗨 VKen。我在 index.html 中提取了@media 部分。但是,“sites36f3.css”中的内容太多了。我在 CSS 中的 .wsite-multicol{position:relative;direction:ltr} 下添加了您的编码,并在 html 中包含了 。但它只强制按指定顺序显示的三个列。它不会响应。 (此外,这也会改变三列的布局。这不是我想要的)
猜你喜欢
  • 2015-03-25
  • 2023-03-10
  • 2023-03-29
  • 1970-01-01
  • 2012-06-19
  • 2012-08-11
  • 1970-01-01
  • 2017-12-19
  • 1970-01-01
相关资源
最近更新 更多