如何在div对象里面的两个div容器之间的空间大小为零?

时间:2017-03-08 11:55:36

标签: html css flexbox containers space

打印屏幕图像:

enter image description here

我的问题是我有两个div容器,里面有很多div窗口。如何使不同容器内的对象之间的边距为零? (见图)。

 <style type="text/css" media="screen">
        html, body { height:100%; background-color: #666666;}
        body { margin:0; padding:0; overflow:hidden; }

#ContainerBlue {
    padding-top:100px;
    display: flex;
    flex-direction: row;     
    justify-content: center; 
    align-items: center;     
    height: 150px;
    background-color:#00F;
}
#ContainerGreen {
    display: flex;           
    flex-direction: column;  
    justify-content: center; 
    align-items: center;     
    height: 250px;
    background-color:#090;
}
.div1 {
    width: 300px;
    margin: 5px;
    text-align: center;     
    background-color:#09F;
    margin-top: 0;
    margin-right: 0;
    margin-bottom: 0;
    margin-left: 0;

}
.div2 {
    width: 300px;
    margin: 5px;
    text-align: center;     
    background-color:#F09;
    margin-top: 0;
    margin-right: 0;
    margin-bottom: 0;
    margin-left: 0;
}

}
</style>
<div id="ContainerBlue"> 

<div class="div1" id="yan1">
<p>div1</p>
</div>

<div class="div2" id="yan2">
<p>div2</p>
</div>

<p align="center" style="color:#FFF; font: bold 18px/30px Tahoma, serif;">Container Blue</p>

</div>

</div>

<div id="ContainerGreen">

<p align="center" style="color:#FFF; font: bold 18px/30px Tahoma, serif;">Container Green</p>
<div class="div1" id="dik1">
  <p>div1</p>
</div>

<div class="div2" id="dik2">
<p>div2</p>
</div>


</div>

1 个答案:

答案 0 :(得分:0)

您必须学习Flexbox,我建议您阅读本指南https://css-tricks.com/snippets/css/a-guide-to-flexbox/

基本上蓝色容器必须是flex-direction: row; justify-content: center; align-items: flex-end; 和绿色flex-direction: column; justify-content: flex-start; align-items: center;

html,
body {
  height: 100%;
  background-color: #666666;
}

body {
  margin: 0;
  padding: 0;
  overflow: hidden;
}

#ContainerBlue {
  padding-top: 100px;
  display: flex;
  flex-direction: row;          
  justify-content: center;
  align-items: flex-end;
  height: 150px;
  background-color: #00F;
}

#ContainerGreen {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  height: 250px;
  background-color: #090;
}

.div1 {
  width: 300px;
  margin: 5px;
  text-align: center;
  background-color: #09F;
  margin-top: 0;
  margin-right: 0;
  margin-bottom: 0;
  margin-left: 0;
}

.div2 {
  width: 300px;
  margin: 5px;
  text-align: center;
  background-color: #F09;
  margin-top: 0;
  margin-right: 0;
  margin-bottom: 0;
  margin-left: 0;
}
<div id="ContainerBlue">
  <div class="div1" id="yan1">
    <p>div1</p>
  </div>
  <div class="div2" id="yan2">
    <p>div2</p>
  </div>
  <p align="center" style="color:#FFF; font: bold 18px/30px Tahoma, serif;">Container Blue</p>
</div>
<div id="ContainerGreen">
  <div class="div1" id="dik1">
    <p>div1</p>
  </div>
  <div class="div2" id="dik2">
    <p>div2</p>
  </div>
  <p align="center" style="color:#FFF; font: bold 18px/30px Tahoma, serif;">
    Container Green</p>
</div>