【问题标题】:How to wrap images around one image in the center?如何将图像环绕在中心的一张图像周围?
【发布时间】:2015-10-08 19:09:15
【问题描述】:

我想要做的是让一个主图像位于页面中心的小巷,然后围绕该中心图像将许多图像环绕在主图像周围。 例子:

相反,即使我向所述图片添加浮动,我也只是让他们查看如下图。

只是为了把它放在那里,我正在使用引导程序。

【问题讨论】:

标签: html image twitter-bootstrap css


【解决方案1】:

这是一个算法,您可以在 PHP/SASS 中使用它来生成类。

var output = '';

// Rows.

    for (var y = 0; y < 9; y++) {

    // Cells.
    for (var x = 0; x < 14; x++) {

        // Clear the area for the main image.
        if (y < 7 && x > 2 && x < 11) {
            output += '0';
        } else {
            output += '1';
        }

        if (x === 13) {
            output += '\n';
        }
    }
}

// Output.
11100000000111
11100000000111
11100000000111
11100000000111
11100000000111
11100000000111
11100000000111
11111111111111
11111111111111

请查看我使用 Bootstrap 构建的示例。只需确保图像的纵横比相同即可。

img {
  max-width: 100%;
  height: auto;
}
.margin-b--10px {
  margin-bottom: 10px;
}
.padding-lr--5px {
  padding-left: 5px !important;
  padding-right: 5px !important;
}

.padding-lr--10px {
   padding-left: 10px !important;
  padding-right: 10px !important;
 }
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" />
<header>
  <div class="container well">
    <h1>Header</h1>
  </div>
</header>

<div class="container">
  <div class="row">
    <div class="col-xs-3">
      <div class="row">
        <script>
          var count = 24;
          while (count) {
            document.write('<div class="col-xs-4 margin-b--10px padding-lr--5px"><img src="http://placehold.it/100x100/eeeeee?text=Column+1"></div>');
            count--;
          }
        </script>
      </div>
    </div>

    <div class="col-xs-6 padding-lr--5px"> 
      <div class="margin-b--10px"><img src="http://placehold.it/700x700"></div>
      
       <div class="row padding-lr--10px">
        <script>
var count = 12;
while(count) { document.write('<div class="col-xs-2 margin-b--10px padding-lr--5px"><img src="http://placehold.it/100x100/333333?text=Column+1"></div>');
count--;
}
        </script>
      </div>
    </div>

    <div class=" col-xs-3 ">
       <div class="row ">
        <script>
var count = 24;
while(count) { document.write('<div class="col-xs-4 margin-b--10px padding-lr--5px "><img src="http://placehold.it/100x100?text=Column+1 "></div>');
count--;
}
        </script>
      </div>
    </div>
  </div>
</div>

【讨论】:

  • 我的意思是这行得通,但有没有办法做到这一点,所有的小图像都在一起而不是分成 3 组?
  • @JonAugood 是的,您可以通过使用position: absolute 对每个块的坐标进行硬编码来做到这一点,我将使用 SASS 生成这种样式。还有一个名为Masonry 的 JavaScript 库,id 会动态地做类似的事情,但我不能保证它会解决这个任务。
  • @JonAugood 这是我用这种方法的核心思想制作的一个 SASS 示例sassmeister.com/gist/caf4133ac9afef4b9129
  • 问题是这很容易放入一个没有确切数量的图像的 php 脚本中,它可能有 2 甚至 56 个。this is what i would love to get in the end
  • 对不起,我是个白痴,但我如何将 JavaScript 和 SASS 与 HTML 放在一起?非常感谢您的帮助,顺便说一句,这意味着很多!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-14
  • 2012-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多