【问题标题】:HTML CSS Responsive Table & CSS BeforeHTML CSS 响应式表格和 CSS 之前
【发布时间】:2013-05-18 17:07:42
【问题描述】:

我的目标是创建在手机上查看时看起来不错的响应式表格设计(宽度低于 480 像素)。

我的表格有以下标记:

<table class="table eventlist">
    <thead>
        <tr>
            <th>Date</th>
            <th>Time</th>
            <th>Duration</th>
            <th>Location</th>
            <th>Cost</th>
        </tr>
    </thead>
    <tr>
      <td data-title="Code">AAC</td>
            <td data-title="Company">AUSTRALIAN AGRICULTURAL COMPANY LIMITED.</td>
            <td data-title="Price" class="numeric">$1.38</td>
            <td data-title="Change" class="numeric">-0.01</td>
            <td data-title="Change %" class="numeric">-0.36%</td>
            <td data-title="Open" class="numeric">$1.39</td>
    </tr>

</table>

还有以下 CSS:

/* Landscape phones and down */
 @media (max-width: 480px) {
    /* Force table to not be like tables anymore */
    table, thead, tbody, th, td, tr {
        display: block;
    }
    /* Hide table headers (but not display: none;, for accessibility) */
    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
        display:none;
    }
    tr {
        border: 1px solid #ccc;
    }
    td {
        /* Behave  like a "row" */
        border: none;
        border-bottom: 1px solid #eee;
        position: relative;
        padding-left: 50%;
        white-space: normal;
        text-align:right;
    }
    td:before {
        padding-right: 10px;
        white-space: nowrap;
        text-align:left;
        font-weight: bold;
    }
    /*
    Label the data
    */
    td:before {
        content: attr(data-title);
    }
}

我的桌子最终看起来像这样:

你认为这是一个很好的用户友好的响应式设计吗?

如何编辑该行:

    td:before {
        content: attr(data-title);
    }

让它读取&lt;th&gt; 的列?

这是一个活生生的例子:JS Fiddle

【问题讨论】:

  • content:attr(…)不能选择其他元素的属性值,只能选择规则实际适用的元素。
  • 所以你不能做 :attr(parent) 什么的?
  • 不,你不能。您可以将该信息冗余地放入每个 TD 元素的另一个 data- 属性中,或者您必须使用 JavaScript 从 TH 获取文本。
  • 公平点,将研究最有效、最干净和最少重复的方法!

标签: html css responsive-design html-table


【解决方案1】:

Re:你觉得这是一个很好的用户友好的响应式设计吗?

它的布局对于单个符号来说看起来很棒,并且在不处于“移动模式”时对于多行来说仍然看起来相当不错,但是如果你打算有多个引号,我认为它最终会看起来很混乱在小屏幕上。您可以考虑删除行之间的边界,只在引号之间添加行以保持视觉上的清洁。

从设计角度来看只是我的 .02。

【讨论】:

    猜你喜欢
    • 2014-11-05
    • 2014-06-01
    • 2021-12-18
    • 2014-11-04
    • 2014-06-05
    • 1970-01-01
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    相关资源
    最近更新 更多