简体   繁体   English

不同大小的div左上对齐

[英]different size divs align top left

CSS CSS

  #box1, #box2, #box3, #box4, #box5, #box6, #box7, #box8, #box9, #box10, #box11, #box12, #box13, #box14, #box15, #box16, #box17, #box18, #box19, #box20 {
    position: relative;
    list-style: none;
    float: left;
clear:left:
}
#box1 {
    width: 60px;
    height: 60px;
    background: yellow;
}
#box2 {
    width: 80px;
    height: 50px;
    background: blue;
}
#box3 {
    width: 40px;
    height: 60px;
    background: red;
}
#box4 {
    width: 200px;
    height: 150px;
    background: green;
}
#box5 {
    width: 60px;
    height: 100px;
    background: red;
}
#box6 {
    width: 70px;
    height: 30px;
    background: blue;
}
#box7 {
    width: 40px;
    height: 80px;
    background: yellow;
}
#box8 {
    width: 90px;
    height: 60px;
    background: red;
}
#box9 {
    width: 50px;
    height: 80px;
    background: blue;
}
#box10 {
    width: 40px;
    height: 60px;
    background: yellow;
}
#box11 {
    width: 60px;
    height: 60px;
    background: yellow;
}
#box12 {
    width: 80px;
    height: 50px;
    background: blue;
}
#box13 {
    width: 40px;
    height: 60px;
    background: red;
}
#box14 {
    width: 100px;
    height: 50px;
    background: yellow;
}
#box15 {
    width: 60px;
    height: 100px;
    background: red;
}
#box16 {
    width: 70px;
    height: 30px;
    background: blue;
}
#box17 {
    width: 40px;
    height: 80px;
    background: yellow;
}
#box18 {
    width: 90px;
    height: 60px;
    background: red;
}
#box19 {
    width: 50px;
    height: 80px;
    background: blue;
}
#box20 {
    width: 40px;
    height: 60px;
    background: yellow;
}

i need align multiple divs top left, without any spaces between divs. 我需要在左上方对齐多个div,并且div之间没有任何空格。 but i need, one div to stay the exact place, where i need (like "green" div place center of the window). 但是我需要一个div来保持我需要的确切位置(例如窗口的“绿色” div位置中心)。 in the fiddle, you can see p17 and p18 not place exactly like other divs. 在小提琴中,您可以看到p17和p18的放置位置与其他div不同。 there are space over those divs. 这些div上方有空间。 i need to put these two divs into that space.how can i fix this without giving margins. 我需要将这两个div放入该space。如何在不增加边距的情况下进行修复。

And if i add new divs, i need automaticaly attach those divs with other divs, the same way in the demo, without space. 如果我添加新的div,则需要自动将这些div与其他div附加在一起,演示中的方式相同,且没有空间。 is there any way to do this. 有没有办法做到这一点。

check the [Demo][1]


|__||  ||     ||   |
|  ||__||_____||   |
|  ||         ||___|
|__||_________||___|
|  ||      ||      |
|__||______||______|

![drawing][2]

i need align all divs in the above demo, like this drawing.

http://jsfiddle.net/ramswarnak/G8dKr/8/ http://jsfiddle.net/ramswarnak/G8dKr/8/

http://i.stack.imgur.com/MbLLf.png http://i.stack.imgur.com/MbLLf.png

please add this css : 请添加此CSS:

#box1, #box2, #box3, #box4, #box5, #box6, #box7, #box8, #box9, #box10, #box11, #box12, #box13, #box14, #box15, #box16, #box17, #box18, #box19, #box20 {   margin:0px; padding:0px; float: left; }

ul, li {  margin:0px; padding:0px; list-style:none;}

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

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