Oracle Content Management 为段落组件内的自适应表提供了一个示例 CSS,该 CSS 允许堆叠移动设备上显示的行数据。
自适应表将根据屏幕大小调整表以有效地显示内容。例如,一个 5 列的表在 Web 页上可以很好地沿水平方向显示,但是当在手机上查看时,以堆叠方式呈现数据可能会更好。请注意,自适应表需要有一个标题行才能正确工作。
请注意,在所生成的如下 HTML 中,为其中的值与列标题文本相匹配的每个表单元格添加了一个 data-label 属性。
<thead> <tr> <th scope="col">ACCOUNT</th> <th scope="col">DUE DATE</th> <th scope="col">AMOUNT</th> <th scope="col">MINIMUM</th> <th scope="col">PERIOD</th> </tr> </thead> <tbody> <tr> <td data-label="ACCOUNT">Visa</td> <td data-label="DUE DATE">04/16/2020</td> <td data-label="AMOUNT">$3,090</td> <td data-label="PERIOD">03/09/2020 - 04/08/2020</td> </tr>
一旦每个单元格中都有该属性,TD 就会在您应用下面的 CSS 规则时相互堆叠。
.scs-paragraph:not(.scs-paragraph-edit) table td { border-bottom: 1px solid #ddd; display: block; text-align: right; } .scs-paragraph:not(.scs-paragraph-edit) table td::before { content: attr(data-label); float: left; font-weight: bold; }
请注意,下面的媒体规则会查询屏幕大小,而且仅在屏幕大小小于 767 像素时才生效。
@media screen and (max-width: 767px) {
有关使用 css 允许所插入的表进行响应的代码示例位于所提供的 StarterTheme 的默认 design.css 中。如果从 StarterTheme 构建站点,则插入到段落内容框中的表将在默认情况下进行响应。要插入表,请执行以下操作:
完成后,切换回到查看模式并选择屏幕宽度小于 767 像素的查看选项,以预览结果。您必须在查看模式下,因为表在编辑模式无法以响应方式工作。
如果您在基于其他主题构建站点时希望使用自适应表,则需要将 StarterTheme design.css 中的代码复制到正在使用的主题的 design.css 文件。
/** * An example CSS of how to render a table responsively. * It enables stacking of row data on mobile devices. * Only do this for view mode (not for edit mode). * * On each cell rendered, it adds a user-defined attribute * 'data-label' with value matching the column header text. */ @media screen and (max-width: 767px) { .scs-paragraph:not(.scs-paragraph-edit) table { border: 0; } .scs-paragraph:not(.scs-paragraph-edit) table caption { font-size: 1.3em; } .scs-paragraph:not(.scs-paragraph-edit) table thead { border: none; clip: rect(0 0 0 0); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; } .scs-paragraph:not(.scs-paragraph-edit) table tr { border-bottom: 3px solid #ddd; display: block; margin-bottom: .625em; } .scs-paragraph:not(.scs-paragraph-edit) table td { border-bottom: 1px solid #ddd; display: block; text-align: right; } .scs-paragraph:not(.scs-paragraph-edit) table td::before { content: attr(data-label); float: left; font-weight: bold; } .scs-paragraph:not(.scs-paragraph-edit) table td:last-child { border-bottom: 0; } }