html - CSS 瓦片定位

标签 html css less

您好,我正在开发使用如下图 block 的网站: enter image description here

如您所见,几乎所有东西都已准备就绪,但有一 block 地砖比其他地砖低。我想把它放在正确的位置,但现在我什么也没想。而且我的工作受阻,除非它能完美地工作。

我的代码更少:

.tile-loop(@index: 1) when (@index <= 6){
  .tile-loop(@index + 1);
  &.t@{index}x1{
    width: (@index * @tile-width) + ((@index - 1) * 2 * @tile-margin);
    height: @tile-height;
  }
  &.t@{index}x2{
    width: (@index * @tile-width) + ((@index - 1) * 2 * @tile-margin);
    height: 2 * @tile-height + 2 * @tile-margin;
  }
  &.t@{index}x3{
    width: (@index * @tile-width) + ((@index - 1) * 2 * @tile-margin);
    height: 3 * @tile-height + 4 * @tile-margin;
  }
  &.t@{index}x4{
    width: (@index * @tile-width) + ((@index - 1) * 2 * @tile-margin);
    height: 4 * @tile-height + 6 * @tile-margin;
  }
  &.t@{index}x5{
    width: (@index * @tile-width) + ((@index - 1) * 2 * @tile-margin);
    height: 5 * @tile-height + 8 * @tile-margin;
  }
  &.t@{index}x6{
    width: (@index * @tile-width) + ((@index - 1) * 2 * @tile-margin);
    height: 6 * @tile-height + 10 * @tile-margin;
  }
}
.tiles {
    padding: 40px 0;
    margin: 0;
    border-bottom: 1px solid @color-black;
    .grid {
      margin-left: -10px;
      margin-right: -10px;
      display: block;
      .tile {
        float: left;
        margin: @tile-margin;
        overflow: hidden;
        position: relative;
        .tile-loop();
      }
      .clear {
        clear: both;
        display: block;
        width: 100%;
      }
    }
  }

HTML:

<div class="tiles">
            <div class="grid">
                <div class="tile t3x4" style="background: red;"></div>
                <div class="tile t3x2" style="background: blue;"></div>
                <div class="tile t3x2" style="background: green;"></div>
                <div class="clear"></div>
                <div class="tile t2x3" style="background: red;"></div>
                <div class="tile t2x1" style="background: blue;"></div>
                <div class="tile t2x2" style="background: green;"></div>
                <div class="tile t2x2" style="background: green;"></div>
                <div class="tile t1x1" style="background: green;"></div>
                <div class="tile t1x1" style="background: green;"></div>
            </div>
        </div>

请帮忙。

最佳答案

仅靠 CSS 无法实现这种布局。有专门的JS解决方案:

关于html - CSS 瓦片定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32822539/

相关文章:

php - 即使未选中,也使复选框出现在 $_POST 数组中

css - IE 11 css-vars-ponyfill 只支持 :root variable, 不支持行内变量

php - CakePHP 2.x 在 CSS 中使用 PHP

css - HTML 如何使日期选择器在 Internet Explorer 11 上可见?

jquery - LESS - 使用 javascript/jquery 饱和颜色代码

javascript - 如何通过JavaScript修改伪类元素的border-bottom颜色?

html - 调整窗口大小时圆圈保持固定

html - 使用 CSS 或 LESS 翻转背景

css - 强制 LESS 导入文件两次

javascript - 当其中的输入具有焦点时,保持非事件导航选项卡显示