【问题标题】:Creating picture gallery with the help of table in html借助 html 中的表格创建图片库
【发布时间】:2021-12-04 04:12:51
【问题描述】:

我在下面有一张图片,我想在 HTML 表格的帮助下设计这样的布局

【问题讨论】:

  • 我建议您尝试一下,然后让我们知道您尝试了什么以及您遇到的具体问题。请参阅I ask a good question?如何操作
  • 这看起来不像表格数据 - 您是否受限于尝试使用表格?
  • @AHaworth 是的,我必须用一张桌子来做
  • 很遗憾,因为网格非常适合 - 表格绝对不是。你能和设置这个限制的人谈谈吗?还是系统需要?
  • 由于您必须使用表格,您可以首先使用它来创建一个 5x5 网格 - 5 行中的每行 5 个单元格,并使它们成为正方形。然后将图像定位为伪元素的背景,这些伪元素的范围超过其“拥有”元素。

标签: html css image html-table row


【解决方案1】:

这里有一些想法可以帮助您入门。

这个 sn-p 首先使用 CSS 网格创建“图库”,然后使用表格。

grid 属性可让您根据行和列在任意位置开始/结束项目。

项目可以重叠,并确保中心的小方块高于其他所有项目,它的 z-index 为 1。

网格将是我的首选方法,但由于您必须使用表格,第二部分创建一个 5 单元格 x 5 单元格的表格,然后将背景图像放在位于相关单元格开头的各种伪元素上,但在某些情况下是宽度的两倍或三倍。

这不是表格的设计目的,但过去我们不得不使用它来解决圆形格式问题。

<style>
            * {
    margin: 0;
    padding: 0;
  }
  body {
    width: 100vw;
    height: 100vh;
  }
  
  .gallery {
    display: grid;
    grid-auto-columns: 20vmin;
    grid-auto-rows: 20vmin;
    grid-gap: 0px;
  }
  
  .pic {
    background-size: cover;
    background-position: center;
  }
  
  .pic:nth-child(1) {
    background-image: url(https://picsum.photos/id/1015/200/300); grid-column: 1 / 3; grid-row: 1 / 3; }
 .pic:nth-child(2) {
      background-image: url(https://picsum.photos/id/1016/200/300); grid-column: 3 / 6; grid-row: 1 / 4; }
 .pic:nth-child(3) {
        background-image: url(https://picsum.photos/id/1018/200/300); grid-column: 3 ; grid-row: 3; z-index: 1;}
 .pic:nth-child(4) {
          background-image: url(https://picsum.photos/id/1019/200/300); grid-column: 1 / 4; grid-row: 3 / 6; }
 .pic:nth-child(5) {
            background-image: url(https://picsum.photos/id/1021/200/300); grid-column: 4 / 6; grid-row: 4 / 6; }
</style>
<div class="gallery">
  <div class="pic">1</div>
  <div class="pic">2</div>
  <div class="pic">3</div>
  <div class="pic">4</div>
  <div class="pic">5</div>
</div>
<style>
.tablegallery {
    border-style: collapse;
  }
  
  .tablegallery,
  .tablegallery *,
  .tablegallery *::before {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    border-style: collapse;
  }
  
  .tablegallery tr td {
    --w: 20vmin;
    width: var(--w);
    height: var(--w);
    display: inline-flex;
  }
  
  .tablegallery tr td {
    position: relative;
  }
  
  .tablegallery tr td::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    display: inline-flex;
  }
  
  .tablegallery tr:nth-child(1) td:nth-child(1)::before {
    background-image: url(https://picsum.photos/id/1015/300/300);
    width: calc(2 * var(--w));
    height: calc(2 * var(--w));
  }
  
  .tablegallery tr:nth-child(1) td:nth-child(3)::before {
    background-image: url(https://picsum.photos/id/1016/200/300);
    width: calc(3 * var(--w));
    height: calc(3 * var(--w));
  }
  
  .tablegallery tr:nth-child(3) td:nth-child(3)::before {
    background-image: url(https://picsum.photos/id/1018/500/300);
    width: calc(1 * var(--w));
    height: calc(1 * var(--w));
    z-index: 1;
  }
  
  .tablegallery tr:nth-child(3) td:nth-child(1)::before {
    background-image: url(https://picsum.photos/id/1019/200/300);
    width: calc(3 * var(--w));
    height: calc(3 * var(--w));
  }
  
  .tablegallery tr:nth-child(4) td:nth-child(4)::before {
    background-image: url(https://picsum.photos/id/1021/200/300);
    width: calc(2 * var(--w));
    height: calc(2 * var(--w));
  }
}
</style>
<table class="tablegallery">
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
  <tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
  </tr>
</table>

【讨论】:

    猜你喜欢
    • 2018-08-04
    • 2012-04-06
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 2010-12-23
    相关资源
    最近更新 更多