【问题标题】:Circular HTML table循环 HTML 表格
【发布时间】:2019-04-11 18:39:09
【问题描述】:

我想知道是否可以制作一个圆形 html 表格? 换句话说,我想把 td 元素放在圈子里。我找到的最接近的例子是this:但这不是一个 html 表。这是一个列表。我尝试了这段代码,但我无法让它按应有的方式工作。

我有一张像this 这样的桌子:

<table class='ctb'>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
  </tr>
</table>

【问题讨论】:

  • 那么为什么不使用您找到的...将其转换为li
  • 我已经试过了,但是没用。
  • 什么不起作用?
  • td 元素未对齐。
  • 为什么一定要用桌子?

标签: html css


【解决方案1】:

使用代码如下:

请看这里:https://codepen.io/leenmalka/pen/rQxEea

 <table class='circle-container'>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
<td>19</td>
<td>20</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>24</td>
<td>25</td>
  </tr>
</table>

CSS:

@import "compass/css3";

@mixin on-circle($item-count, $circle-size, $item-size) {  
  position: relative;
  width:  $circle-size;
  height: $circle-size;
  border-radius: 50%;
  padding: 0; 

  > * {
    display: block;
    position: absolute;
    top:  50%; 
    left: 50%;
    margin: -($item-size / 2);
    width:  $item-size;
    height: $item-size;

    $angle: (360 / $item-count);
    $rot: 0;

    @for $i from 1 through $item-count {
      &:nth-of-type(#{$i}) {
        transform: rotate($rot * 1deg) translate($circle-size / 2) rotate($rot * -1deg);
      }

      $rot: $rot + $angle;
    }
  }
}

.circle-container tr{
  @include on-circle($item-count: 25, $circle-size: 20em, $item-size: 1em); 
  margin: 5em auto 0;
  border: solid 5px tomato;

  td { 
    display: block; 
    max-width: 100%; 
    border-radius: 50%;
    filter: grayscale(100%);
    border: solid 5px tomato;
    transition: .15s;

    &:hover {
      filter: grayscale(0);
    }
  }
}

【讨论】:

  • 谢谢,看起来很棒。如果你不介意,只是一个小问题。我必须使用 div 吗?
  • 因为在 li 里面是 img 在原来的我尝试使用相同的...原因是:&gt; * { in scss
  • 但你可以在没有我编辑的情况下做到这一点答案:codepen.io/leenmalka/pen/rQxEea
  • 太棒了!我会用这个:)
猜你喜欢
  • 1970-01-01
  • 2018-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-14
  • 2017-02-11
相关资源
最近更新 更多