项目之间有填充/边距的网格布局

时间:2015-05-29 06:36:25

标签: html css css3 grid

如何在网格布局上的项目之间添加空格(填充)?我尝试将填充添加到div但空格不相等。

div{
   width:calc(100% / 3);
  padding:10px;
box-sizing:border-box;
    float:left;
    
}

img{
    width:100%;
    border:1px solid;
    display:block;
}

body{
    margin:0;
    padding:0;
}
<div><img src="http://placehold.it/200x200"/></div>
<div><img src="http://placehold.it/200x200"/></div>
<div><img src="http://placehold.it/200x200"/></div>
<div><img src="http://placehold.it/200x200"/></div>
<div><img src="http://placehold.it/200x200"/></div>
<div><img src="http://placehold.it/200x200"/></div>
    

1 个答案:

答案 0 :(得分:2)

 

  div{
   padding:5px;
   box-sizing:border-box;
   overflow:hidden;
  }

  div > div{
      width:calc(100% / 3);
      float:left;   
    }

img{
    width:100%;
    border:1px solid;
    display:block;
    box-sizing:border-box;
}

body{
    margin:0;
    padding:0;
}
<div>
    <div><img src="http://placehold.it/200x200"/></div>
    <div><img src="http://placehold.it/200x200"/></div>
    <div><img src="http://placehold.it/200x200"/></div>
    <div><img src="http://placehold.it/200x200"/></div>
    <div><img src="http://placehold.it/200x200"/></div>
    <div><img src="http://placehold.it/200x200"/></div>
</div>