简体   繁体   English

如何将Div彼此包裹

[英]How to wrap Div's around each other

I am using flexbox. 我正在使用flexbox。 I have 10 div's that I want to all wrap around each other as much as possible without leaving any space in between. 我有10个div,它们都希望彼此尽可能地互相缠绕,而在两者之间不留任何空间。

What I want to do is have "4" start at the right side of "1" instead of going down into another row. 我想做的是让“ 4”在“ 1”的右侧开始,而不是向下一行。 How would I go about doing this? 我将如何去做呢? Any jquery plugins to make this easier? 任何jquery插件可以使此操作更容易吗? I'd like to know the basics behind doing this though without having to rely on plugins. 我想了解执行此操作的基本知识,尽管不必依赖插件。

https://jsfiddle.net/414yhvxd/ https://jsfiddle.net/414yhvxd/

 .container{ display:flex; flex-wrap:wrap; flex-direction:row; height:900px; background:gray; max-height:900px; } .box{ color:white; font-size:30px; text-align:center; background:black; width:200px; height:200px; margin:2px; } .type1{ height:300px; } .type2{ width:500px; } .type3{ height:40px; width:50px; } .type4{ height:600px; } 
 <div class="container"> <div class="box type1">1</div> <div class="box type2">2</div> <div class="box">3</div> <div class="box type3">4</div> <div class="box">5</div> <div class="box type4">6</div> <div class="box">7</div> <div class="box">8</div> <div class="box">9</div> <div class="box">10</div> </div> 

You should break each section you want to be beside each other into different div containers. 您应该将要彼此相邻的每个部分分成不同的div容器。 You will also need to make sure that the container div, div with class "container", is the exact width you want. 您还需要确保容器div(类为“容器”的div)是您想要的确切宽度。

The basic principle: https://jsfiddle.net/414yhvxd/1/ 基本原理: https//jsfiddle.net/414yhvxd/1/

<div class="container">
  <div>
    <div class="box">1</div>
    <div class="box">2</div>
    <div class="box">3</div>
  </div>
  <div>
    <div class="box type3">4</div>
    <div class="box">5</div>
    <div class="box type4">6</div>
    <div class="box">7</div>
    <div class="box">8</div>
    <div class="box">9</div>
    <div class="box">10</div>
  </div>
</div>  

.container{
   display:flex;
  flex-wrap:wrap;
  flex-direction:row;
  height:900px;
  background:gray;
  max-height:900px;
}

.box{
  color:white;
  font-size:30px;
  text-align:center;
  background:black;
  width:200px;
  height:200px;
  margin:2px;
}
.type1{
  height:300px;
}
.type2{
  width:500px;
}
.type3{
  height:100px;
  width:50px;
  }
.type4{
  height:600px;
}

As I'm not entirely sure exactly how you want your boxes split, this should give you a baseline in order to manipulate it as you want. 由于我不能完全确定要如何拆分框,因此应该为您提供一个基线,以便根据需要进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM