【问题标题】:HTML/CSS: Responsive table [duplicate]HTML / CSS:响应表[重复]
【发布时间】:2021-05-03 09:44:00
【问题描述】:

我的 wordpress 端有一张这样的表格:

.center {
  margin-left: auto;
  margin-right: auto;
}

.text-center-row>th,
.text-center-row>td {
  text-align: center;
}
<table style="border: none;" class="center">
  <tbody>
    <tr class="text-center-row">
      <td style="border: none;">Icon 1</td>
      <td style="border: none;">Icon 2</td>
      <td style="border: none;">Icon 3</td>
      <td style="border: none;">Icon 4</td>
    </tr>
    <tr class="text-center-row">
      <td style="border: none;">Text with Link 1</td>
      <td style="border: none;">Text with Link 2</td>
      <td style="border: none;">Text with Link 3</td>
      <td style="border: none;">Text with Link 4</td>
    </tr>
  </tbody>
</table>

不幸的是,这不适合较小的移动屏幕,所以我想将此表格更改为带有 HTML/CSS 的响应式表格。我在互联网上找到了很多例子,但不幸的是没有一个更合适。我想在移动视图上有这样的表格:

  Icon 1
Text&Link 1
  Icon 2
Text&Link 2
  Icon 3
Text&Link 3
  Icon 4
Text&Link 4

以某种方式需要获取一列并将其用作下面的一行。

有人可以帮忙写一个代码 sn-p 吗? 谢谢和亲切的问候 NKL

【问题讨论】:

    标签: html css mobile html-table responsive-design


    【解决方案1】:

    使用 DIVS

    .center {
      margin-left: auto;
      margin-right: auto;
    }
    
    .text-center {
      text-align: center;
    }
    
    #iconContainer { text-align:center;  width: 100vw; }
    #iconContainer div { display:inline-block; padding: 0 5px 0 5px; }
    <div id="iconContainer">
    <div class="text-center">Icon 1<br/>Text with Link 1</div>
    <div class="text-center">Icon 2<br/>Text with Link 2</div>
    <div class="text-center">Icon 3<br/>Text with Link 3</div>
    <div class="text-center">Icon 4<br/>Text with Link 4</div>
    <div class="text-center">Icon 5<br/>Text with Link 5</div>
    </div>

    小屏幕:

    【讨论】:

    • 嗨,总的来说,这可以按需要工作,谢谢。不幸的是,CSS 中的 #container 块正在修改我完整的 Wordpress 方面,并影响了所有页面的总体视图。也许我的 wordpress 主题已经使用了这个 #container 关键字?是否有可能使用不同的命名来解决冲突?
    • 好的,随便改一下
    • 是的,我试过用不同的名字,这似乎不是问题。问题是,这个div { display:inline-block } 覆盖了在页面上多次使用的普通div。是否有可能以某种方式改变这一点?
    • 当然。很简单。查看更新
    • 谢谢。 “FLEX”关键字是完美的。这里有一些链接:css-tricks.com/snippets/css/a-guide-to-flexboxblog.kulturbanause.de/2019/06/… 感谢您的帮助!不幸的是,这个主题已经关闭(但参考答案主题不适合我的需要),否则我会在这里展示我的解决方案......
    猜你喜欢
    • 2021-12-18
    • 1970-01-01
    • 2017-05-20
    • 2013-05-18
    • 2018-03-15
    • 2014-11-05
    • 2017-04-03
    • 2014-06-01
    • 2020-12-02
    相关资源
    最近更新 更多