简体   繁体   English

消除div之间的差距?

[英]remove gap between div?

I have a question, I tried to search on google but unluckily I didn't find any answer... 我有一个问题,我尝试在Google上搜索,但不幸的是我没有找到任何答案...

So i want to remove gap between DIVs. 所以我想消除DIV之间的差距。 I have a small PHP application which shows users images in a div with some other info, DIV width is 250px and DIV height is auto because I don't know the length of content and I also didn't know the number of the DIV because i fetch data from MYSQL. 我有一个小型的PHP应用程序,它在div中向用户显示其他一些信息的图像,DIV宽度为250px,DIV高度为自动,因为我不知道内容的长度,我也不知道DIV的数量,因为我从MYSQL获取数据。

Here is a screen-shoot of my web page: 这是我的网页的屏幕截图: 这是我的网页的屏幕截图

And my code is: 我的代码是:

<style>
#det
{
width:250;
height:auto;
max-height:400px;
border-bottom:3px solid darkred;
background-color:white;
float:left;

padding:0px;
margin:0 auto;
border-radius:5px;
}

HTML 的HTML

<div id='det'>
<img src='$user_image'><p>some text</p>
</div>

I want to remove gap between DIV and show it how a magazine-style look like. 我想消除DIV之间的差距,并向它展示杂志风格的样子。 Example: masonry.desandro.com . 例如: masonry.desandro.com Currently i used float:left but it's not working properly and maybe because I didn't set height. 目前我使用了float:left但是它不能正常工作,也许是因为我没有设置高度。 Is there anyway to solve this without set div height? 有没有解决这个问题,而无需设置div高度?

Thanks 谢谢

Use flex fluid layout for showing variable height elements properly. 使用柔韧性流体布局正确显示可变高度的元素。

.container {
  display: flex;
  flex-wrap: wrap;
}

.item {
  width: 179px;
  flex-grow: 0;
  flex-shrink: 0;
}

https://jsfiddle.net/w4pfxk2x/ https://jsfiddle.net/w4pfxk2x/

You should use display:inline-block; 您应该使用display:inline-block; instead of float:left; 而不是float:left; and your problem will be fixed. 您的问题将得到解决。

.det{
width:250;
height:auto;
max-height:400px;
border-bottom:3px solid darkred;
background-color:white;
display:inline-block;
padding:0px;
margin:0 auto;
border-radius:5px;
vertical-align:top
}

https://jsfiddle.net/IA7medd/haqkxkmb/ https://jsfiddle.net/IA7medd/haqkxkmb/

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

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